Code

Opened 9 years ago

Closed 8 years ago

Last modified 7 years ago

#359 closed defect (duplicate)

Simplified assignment and lookup for related fields

Reported by: garthk@… Owned by: adrian
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Further to #122, I'd love to see a simpler syntax for direct assignment and reference of objects in related tables. It'd eliminate the last big separation (in my mind, at least) between how people work with normal Python objects and how they need to work Django database-backed objects. All you'd have left is .save(), which I'm all for keeping.

from django.core import meta

class Person(meta.Model):
    name = meta.CharField(maxlength=200)
    
class CourtCase(meta.Model):
    plaintiff = meta.ForeignKey(Person)
    defendant = meta.ForeignKey(Person)

me = persons.get_object(name__exact="garthk")
you = persons.get_object(name__exact="hugo-")
case = courtcases.CourtCase()
case.defendant = me
case.plaintiff = you
case.save()
print case.defendant.name

We'd also want to retain support for {{case.defendant_id = me.id}} for those who tend to think more in terms of the database structures than the Python structures. I'm definitely in the latter category, but I know plenty of people in the former.

Attachments (0)

Change History (6)

comment:1 Changed 9 years ago by Manuzhai

I agree this would be much nicer. I may look into implementation later.

comment:2 Changed 9 years ago by rmunn@…

I'd also like to see this happen. Since I'm about to drop off the face of the 'Net for at least a week, though, I can't commit to doing any work on the implementation. :-)

comment:3 Changed 9 years ago by anonymous

  • Owner changed from adrian to anonymous
  • Status changed from new to assigned

comment:4 Changed 9 years ago by adrian

  • Owner changed from anonymous to adrian
  • Status changed from assigned to new

comment:5 Changed 9 years ago by adrian

  • Status changed from new to assigned

comment:6 Changed 8 years ago by adrian

  • Resolution set to duplicate
  • Status changed from assigned to closed

Closing this ticket because it's been superceded by the DescriptorFields discussion.

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.