Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Zenobia
Nov 11, 2007

i can't see the captcha image
where is it
I'm trying to filter objects by a foreign key.

In my models.py I have:
code:
user = models.ForeignKey(User, unique=True)
as a field for this particular class.

What I'd like to do is get all entries added by this user, but
code:
Entry.objects.filter(user='zenobia')
gives me nothing, although I'm sure the entered user string is correct.
Filtering by slug works without trouble, so I'm guessing it has something to do with the field being a ForeignKey?

Adbot
ADBOT LOVES YOU

Zenobia
Nov 11, 2007

i can't see the captcha image
where is it
This is probably common knowledge, but I just couldn't find the right search terms.
I'm basically following the Django book, but I'd like to know how I can include a, for example, login form in my base template and not having to repeat the code in every view that I want the user to be able to login from. Currently I just link users to a login page.
Could anyone help me with this?

Zenobia
Nov 11, 2007

i can't see the captcha image
where is it
Thanks for all the help I've gotten already (especially Bonus).

I'd like to auto-populate the "user" field in a model (foreign key to User) with the current request.user when a ModelForm of this model is submitted. I've searched and found a couple of guides, but they're all from ye olde times before ModelForm. I don't really understand how to use the information in the docs, since I'm currently using generic views.
Do I need to write my own form handling view for this, or is there an easy way to implement this using the update_object generic view?

Zenobia
Nov 11, 2007

i can't see the captcha image
where is it
I saw that in the docs, but I have no idea where to put that code or if it's possible to use this in conjunction with generic views.

Zenobia
Nov 11, 2007

i can't see the captcha image
where is it
Thanks, I thought it might be possible to subclass the generic views or that the snippet Bonus provided would redefine the save function in the forms file. I wrote my own view to handle the form and everything works perfectly now.

Zenobia fucked around with this message at 12:26 on Jul 29, 2008

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply