Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » (newcomer) Directly attributing a many-to-many relationship as in RoR possible? [RSS Feed]

#1 March 27, 2008 03:41:00

Russell K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

(newcomer) Directly attributing a many-to-many relationship as in RoR possible?


On Tue, Mar 18, 2008 at 4:54 AM, Spiderspanky
<> wrote:
>
> Hi Russ,

Hi John. Apologies for the delay in replying - this message got buried
in my inbox.

> > 2) Longer term, this is something that will be addressed by ticket #6095
> >
> >http://code.djangoproject.com/ticket/6095>
> Whereas, withouth wanting to bash Django, I actually did expect that
> said concept would already be available in Django in a way as elegant
> as described in this ticket discussion if it was available at all in
> Django, since in RoR it's done nicely since 2 years ago.

... and Django has had a neat built-in admin site since day one, which
Rails _still_ doesn't have all these years later. How can Rails
developers sleep at night while this horrendous deficiency still
exists!

Seriously - there are things Django does that Rails doesn't, and vice
versa. We have a plan for fixing the m2m problem, once we've got the
kinks in the implementation sorted out.

> Again re 1) though:
> I don't quite get some of the code in the section "play around with
> the API", if you don't mind my asking.
>
> The last two lines of code:
> Why doesn't Python/Django return for what article John Smith is the
> Main Writer?

Because this is another step in the relation. This is a 'how to do the
workaround' example, so you can't step directly from the author to the
article. You need to get the writer from the author, and the article
from the writer.

> And if John Smith was a writer for a different article a2 also, how
> would the ouput look like?

You would get two Writer entries for John Smith (plus the one for Jane).

> The first two lines of code in said section:
> How does the API know that a Main Writer is a higher position than a
> Contributor? Is this derived implicitly from that fact that John is
> saved first as a reporter for that article and Jane second? That would
> require arranging the actual codelines to suit that.

No - they are sorted. The ".order_by('-position')" clause sorts
results in reverse order on the position field. Position is a
charfield, so "Main Writer" comes before "Contributor" in reverse
alphabetical order.

> I'm probably way off-track here, but is this the normal way to program
> in Python or in Django? I'm just trying to understand and learn in
> order to be prepared, not to provoke or bash. Can I easily derive
> which information is ordered by way of order of save()s?

Almost never. The database will just give you rows. The order of those
rows will be unpredictable in the general case, although in simple
tests they will probably be returned in insertion order. If you want
predictable order, you will need to add a sorting clause (order_by()
in a query, or adding an ordering field to the Meta block for your
model. More details in the docs).

> Generally:
> I assume writer_set is automatically defined by Django which derives
> this task of defining it and the name from the Writer class?

Yes, but the name can be customized. Again, more details in the docs.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

  • Root
  • » Django
  • » (newcomer) Directly attributing a many-to-many relationship as in RoR possible? [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support