Consider I have defined the following models:
class Tag(models.Model):
name = models.CharField(max_length=20)
class Entry(models.Model):
title = models.CharField(max_length=100)
date = models.DateField()
tags = models.ManyToManyField(Tag)
and the following model form:
class EntryForm(forms.ModelForm):
tags = CharField(max_length=100, label='Tags', required=False)
class Meta:
model = Entry
Basically I have an entry with tags. The tags are not necessarily already created. I need to receive a filled entry form and save it with tags.
I can do that easily if I don't have the ManyToMany relation in the Entry. But with it I first need to save the tags, then add the saved tags to the entry and then save the entry. Which means I have to override the EntryForm's save() method.
I saw this question already, but it looks different. In my case I need to save only the tags, and the rest should be able use ModelForm's default save().
I presented a simplified example. In real one I have much more fields in the Entry. What is your recommendation for writing EntryForm's save() method in a django way?