How to avoid duplication of lines for creation (POST) in Django-Tastypie?

Am I trying to avoid duplicate row insertion in django-tastypie model? I see how I can do unique in this area, but now, how to ensure that the whole creation / message is unique. I noticed that there is a way to do this with django-piston inside the handler class as follows:

  def create (self, request):
         attrs = self.flatten_dict (request.POST)
         try:
             inst = self.model.objects.get (** attrs)
             return rc.DUPLICATE_ENTRY
         except self.model.DoesNotExist:
             inst = self.model (** attrs)
             inst.save ()
             return inst
         except self.model.MultipleObjectsReturned:
             return rc.DUPLICATE_ENTRY 

Let me know if I cannot find an answer somewhere, I would like to be able to send files that may have duplicate lines (for example, bank transaction files with overlapping time periods).

+4
source share

Source: https://habr.com/ru/post/1402810/


All Articles