Model.objects.create as default

40 views
Skip to first unread message

degnon...@gmail.com

unread,
Feb 6, 2021, 1:42:40 PM2/6/21
to Django users
hi, say I have this model

class Event(models.Model):
  ...
  metrics = models.OneToOneField("evmetrics.Metrics", on_delete=models.PROTECT,
default=Metrics.objects.create)

I want to be sure of what I'm writing here, for each new Event object created, a new Metrics object will be create and link to the event by a OneToOne relationship, is there any chance this is really bad code or this could be a problem ?

Rama akki

unread,
Feb 10, 2021, 12:42:13 AM2/10/21
to django...@googlegroups.com
Better, you can use signal or model manager with one-to-one relationship

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/541e8075-0ded-41cd-a565-e552c66a0183n%40googlegroups.com.

Tobi DEGNON

unread,
Feb 10, 2021, 5:19:35 PM2/10/21
to django...@googlegroups.com
ok thanks

You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/Iw83-HaVevc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAmXcB67yeFY%2Bv-ASUKu3bVEUVUPy%3Difz2fehg%2BKmhd7nDkBnw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages