django-sqrl-2/sqrl/managers.py

25 lines
758 B
Python
Raw Normal View History

2019-08-14 11:52:59 -05:00
# -*- coding: utf-8 -*-
from django.db import models
class SQRLNutManager(models.Manager):
"""
Customer :obj:`.models.SQRLNut` model manager.
"""
def replace_or_create(self, session_key, **kwargs):
"""
This method creates new :obj:`.models.SQRLNut` with given parameters.
If nut already exists, it removes it before creating new nut.
Parameters
----------
session_key : str
Key of the session. All nuts with matching session will be removed.
**kwargs
Kwargs which will be used to create new :obj:`.models.SQRLNut`
"""
self.get_queryset().filter(session_key=session_key).delete()
return self.create(session_key=session_key, **kwargs)