On Mon, Nov 2, 2009 at 11:40 PM, Jacob Kaplan-Moss <[email protected]> wrote:
>
> Hi Russ --
>
> I'm +1 on merging the patch immediately. I have some feedback on the
> couple of issues you raised below, but I see no reason they can't be
> addressed after merging.
>
> On Fri, Oct 30, 2009 at 3:33 AM, Russell Keith-Magee
> <[email protected]> wrote:
>> The automatically generated m2m model is the equivalent of the following:
>>
>> class Book_authors:
>>    book = ForeignKey(Book)
>>    author = ForeignKey(Author)
>
> I can't quite see how you'd "get at" this model class, should I want
> it. I guess I could go through `django.db.models.loading.get_model`,
> right? Is the intention to make this class an internal implementation
> detail? If so, then it's just fine that it's not directly available...
> but if this model is supposed to be available to public code then do
> we need a better way to expose it?
>
> I ask because...
>
>>  * #11795 (allowing admin inlines for m2m objects) becomes a 2 line
>> fix, plus documentation. Since this patch makes m2m tables fully
>> fledged Django objects, you can reference them in the models= line of
>> a TabularInline. m2m inlines are actually possible without any change
>> on top of this patch - but with two extra lines, it becomes a lot
>> easier to use.
>
> ... it seems that to make this fix you'd need to somehow "get at"
> those related models. Right?

Correct - and that's the 2 line fix.

As is, there are four ways to get at the through model via various
convoluted channels:

1. get_model('myapp','Book_authors')

2. Book._meta.get_field('authors').rel.through

3. Book.authors.field.rel.through

4. Author.book_set.related.field.rel.through

None of these are particularly pretty, but they work. However, 3 and 4
can be made humane with very little effort. If we put a readonly
'through' property on the m2m descriptors (forward and reverse) that
completes the rest of the lookup, it becomes possible to say:

3. Book.authors.through

4. Author.book_set.through

So, your admin declaration becomes:

class AuthorInline(TabularInline):
    model = Book.authors.through

class Book(ModelAdmin):
    inlines = [AuthorInline]
    exclude = ['authors']

This technique works for _any_ m2m intermediate table - explicit or implicit.

>>  * #5537 becomes a purely documentation fix. If you use a related_name
>> of '+' on your model, the related object is hidden. The only question
>> here is whether we want to document this change - so far the '+' thing
>> has been an internal implementation issue, so we need to decide if we
>> want to make this official.
>
> `related_name="+"` makes me wince. It's entirely unclear (to me) that
> "+" means "hide the reverse relation", so I'm -1 on documenting that
> fact.
>
> However, it's useful behavior, so why not just add a constant to
> `django.db.models` for that? It'd then look like::
>
>    fk = models.ForeignKey(ToModel, related_name=models.HIDE_RELATED)

Sounds reasonable to me. The important part is actually deciding that
it's useful behavior that we want to encourage - the discussion on
#5537 hasn't got consensus that it is.

Yours
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to