Saturday, November 26, 2022

Re: join on plain integerfield

It only uses 2 columns, the "type" of the relation and the id of the
related object. That's why I thought it might be a good fit for your
use case. If you can't use it as-is because your "type" column is a
boolean instead of a foreignkey to ContentType, you can look at the
GenericForeignKey code[1] to see if you can copy and adapt it.

[1] https://github.com/django/django/blob/main/django/contrib/contenttypes/fields.py#L25

On Fri, Nov 25, 2022 at 07:43:47AM +0100, Marek Rouchal wrote:
> Thanks Ryan, that looks promising. I have to dig deeper, but upon first
> read I saw that an additional field would be required in the model
> definition; question: would that also require an additional column in the
> database (which I could not afford), or is it purely a „meta" kind of field
> for ORM purposes only?
>
>
> Ryan Nowakowski <ryan@fattuba.com> schrieb am Mo. 21. Nov. 2022 um 20:41:
>
> > That's sort of how generic relations[1] work. You might be able to make it
> > fit.
> >
> > [1]
> > https://docs.djangoproject.com/en/4.1/ref/contrib/contenttypes/#generic-relations
> >
> > --
> > 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/1YTjSHaj0x0/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to
> > django-users+unsubscribe@googlegroups.com.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/django-users/C5E28F70-7521-4CFF-A43E-1B5576D144CF%40fattuba.com
> > <https://groups.google.com/d/msgid/django-users/C5E28F70-7521-4CFF-A43E-1B5576D144CF%40fattuba.com?utm_medium=email&utm_source=footer>
> > .
> >
>
> --
> 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+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Bb80mBJqZWsBg_QiTY7O-0dzxcCXEhYv6-PQQ_ukV895bs%2Bww%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20221126134731.GB8954%40fattuba.com.

No comments:

Post a Comment