Answer the question
In order to leave comments, you need to log in
How to automatically fill an empty model field with a link?
There is this model:
class Vote(models.Model):
record = models.OneToOneField(Record)
voted_by = models.ForeignKey(UserProfile)
Answer the question
In order to leave comments, you need to log in
If you need to add a connection when creating a model Vote
, then you can overload the methodsave()
class Vote(models.Model):
def save(self, *args, **kwargs):
#Проверяем, что объекта еще нет в базе
if self.pk is None:
record = Record.objects.create(#заполняете нужные поля)
self.record = record
super(Vote, self).save(*args, **kwargs)
Record
, you can simply take it from the database, and not create a new one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question