N
N
newvasyuki2020-12-02 16:05:26
Django
newvasyuki, 2020-12-02 16:05:26

How to get new entries in inlineformset on save and set field value?

class Foo(models.Model):
  name = model.CharField(max_length=255)


class Bar(models.Model):
  parent = models.ForeignKey(Foo, on_delete=models.CASCADE)
  name = model.CharField(max_length=255)
  created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)


BarInlineFormset = inlineformset_factory(Foo, Bar, extra=3)


Further, the formset is edited by the user, and when saving, you need to 1) somehow get/understand what new instances, 2) set created_by to the current user from request.user. How to solve this problem in a typical way in django?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question