On 2/10/2013 10:20am, Russell Keith-Magee wrote:
>
> On Wed, Oct 2, 2013 at 6:19 AM, Mike Dewhirst <miked@dewhirst.com.au
> <mailto:miked@dewhirst.com.au>> wrote:
>
> Consider a bunch of substances and a bunch of papers written by
> various researchers. Some of the papers apply to more than one
> substance and a substance can have multiple papers. Here are the
> models ...
>
> class Paper_Substance(models.Model):
> paper = models.ForeignKey('Paper', null=True, blank=True)
> substance = models.ForeignKey('Substance', null=True, blank=True)
> reference = models.CharField(max_length=8, null=True, blank=True)
> ...
>
> class Paper(models.Model):
> papers = models.ManyToManyField('__Substance',
> through='Paper_Substance')
> ...
> title = models.CharField(max_length=__200)
> url = models.URLField(null=True, blank=True)
> ...
>
> In the Admin I want to add none, one or more Papers to any
> Substance. I can do this but I can only see the the content of
> Paper_Substance records instead of Paper records. In particular I
> want to display the URL of the paper. This is the admin snippet ...
>
> class PapersInline(admin.__StackedInline):
> model = Paper.papers.through
> fk_name = 'substance'
>
> Is this possible?
>
>
> Well… maybe.
>
> The easy answer is no.
Thanks Russell. I'm really keen on "easy". That lets me off the hook :)
Cheers
Mike
You can't display an inline for the Paper model
> directly because an intermediate model is involved. Even though the
> 'extra' data is nullable, Django's admin forces the option to be
> displayed. This is a known limitation of the intermediate models in
> general; there are tickets floating around to address this limitation.
>
> Depending on what is actually acceptable as a final solution, you
> *might* be able to work around the problem, though. If the only
> requirement is that you display the URL for the related Paper instance,
> you might be able to write a custom ForeignKey widget that the Inline
> will use to display the remote Paper instance, and modify the output of
> that widget to display whatever details about the Paper instance you
> want. It's not going to be simple, and it probably won't be pretty
> either, but it should be *possible*.
> Yours,
> Russ Magee %-)
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJxq84_8U0iqUGB_SVKG9KkvQkEFKtPrKr_vfiq72x-wmTtn6g%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.
--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/524B835F.7010707%40dewhirst.com.au.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment