List Info

Thread: prepopulate_from




prepopulate_from
user name
2006-06-28 18:58:11
Hi all

I'd like to set up an admin form that will use something
like a
SlugField's prepopulate_from to fill several text fields
with
information from foreignkey, float, and other fields. It
doesn't seem
Django's current function will meet my needs, but I'm
trying to figure
out the best way to proceed before I start hacking around
with
Javascript. Here's a bit of pseudocode:

class Player(models.Model):
    team = models.ForeignKey(Team)
    team_text = models.CharField(maxlength=100,
prepopulate_from=('team',))

This example makes the text field seem redundant, but it's
really not.
It's also just as likely that I'm completely missing the
obvious
solution. Got any suggestions? 

Thanks,
Chase


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

prepopulate_from
user name
2006-06-29 04:02:29
On 6/28/06, Chase <chase.davisgmail.com> wrote:
> I'd like to set up an admin form that will use
something like a
> SlugField's prepopulate_from to fill several text
fields with
> information from foreignkey, float, and other fields.
It doesn't seem
> Django's current function will meet my needs, but I'm
trying to figure
> out the best way to proceed before I start hacking
around with
> Javascript. Here's a bit of pseudocode:
>
> class Player(models.Model):
>     team = models.ForeignKey(Team)
>     team_text = models.CharField(maxlength=100,
> prepopulate_from=('team',))
>

If Django's current function doesn't handle this, I would
consider
that a bug. What does it currently do -- include the raw ID
value of
the team rather than the display name?

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

prepopulate_from
user name
2006-06-29 13:26:26
Weird ...

If I add prepopulate_from to a handful of fields, the text
fields
typically prepopulate fine (although sometimes they don't),
but nothing
populates from the ForeignKeys. FireBug says it's not a
Javascript
error, so I assumed it was a framework limitation. I'll
give it another
shot later this morning and I'll post the code if it's
still not
working.

Thanks,
Chase


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

prepopulate_from
user name
2006-06-29 15:27:53
Still no dice. I'm noticing a couple quirks. The first
comes where I
have two fields prepopulating from one:

Class Event(models.Model):
    name = models.CharField(maxlength=200)
    slug =
models.SlugField(prepopulate_from=("name",))
    print_title = models.CharField(maxlength=200,
prepopulate_from=("name",))

Slug prepopulates, but not print_title. However, if I take
the
prepopulate_from option out of slug, print_title
prepopulates fine. The
other issue comes with ForeignKey fields:

class Event(models.Model):
    venue_db = models.ForeignKey(Place)
    print_venue = models.CharField(maxlength=200,
prepopulate_from("venue_db",))

In this case, print_venue doesn't fill with anything. Even
weirder,
slug no longer prepopulates from name under these
conditions. It's like
prepopulate stops functioning. According to FireBug, there
are still no
Javascript errors. The __str__method in Place returns an
equivalent of
self.name, as it should.

Following that, I tried to prepopulate only slug from
venue_db, but
that didn't work either. I restarted Apache following every
change, so
although I'm probably overlooking something, I'm at least
not
overlooking that. According to the docs, prepopulate_from is
only
classified as an extra option for SlugFields. If that's
true, I can
understand why this doesn't work. But otherwise, I'm
stumped.

Thanks,
Chase


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )