Code

Opened 2 years ago

Closed 2 years ago

#18061 closed Uncategorized (duplicate)

GenericRelation doesn't play well with proxy models

Reported by: anonymous Owned by: nobody
Component: Uncategorized Version: 1.4
Severity: Normal Keywords:
Cc: charette.s@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Take the following models:

class Person(models.Model):
    """
    Teenager (let's say this has the content type ID 1)
    """
    age = models.IntegerField()


class Teenager(Person):
    """
    Teenager (let's say this has the content type ID 2)
    """
    class Meta:
        proxy = True


class Pimple(models.Model):
    """
    A pimple.
    """
    content_type = models.ForeignKey(ContentType)
    object_id = models.IntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')
    color = models.CharField()

Now, if I create a PimpleInline on the TeenagerAdmin, and then create Pimple records with the main PimpleAdmin, setting the content type to Teenager (ie, 2), you would think that a refresh on the TeenagerAdmin would reveal my new pimple in the inline list, but it doesn't. This has to do with the GenericRelation.contrib_to_class which attaches an updated queryset along the way, filtering by the content type of the proxy's parent model.

Attachments (0)

Change History (2)

comment:1 Changed 2 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Please disregard the missing max_length argument and the duplicate "Teenager" pasted into Person.__doc__.

comment:2 Changed 2 years ago by charettes

  • Cc charette.s@… added
  • Resolution set to duplicate
  • Status changed from new to closed

This is a duplicate of #17648.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.