Hi,
I'm having some trouble getting data from a database with foreign-keys.
Normally a query-set retrieved like this, obj =
model.objects.all().filter(id=pk).select_related(), would give me the table
row data, and the related row data from another table defined in the model,
of the default da
I just found a nice blog post:
http://push.cx/2007/django-template-tag-for-dictionary-access
That seems to work nicely. =)
On Jan 1, 2:42 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
> Thanks Todd.
>
> I came up with this:
>
> def get_services():
>d = {}
>for p in Profile.objects.all():
>
Thanks Todd.
I came up with this:
def get_services():
d = {}
for p in Profile.objects.all():
for s in p.services.all():
if not d.has_key(s.slug):
d[s.slug] = s.name
return d
So I pass this function as extra context (service_list) to the
template. When I try
maybe you'll use a set on the result so you don't have duplicates,
a least i think so..
On Jan 1, 2:04 am, "Todd O'Bryan" <[EMAIL PROTECTED]> wrote:
> There's probably an easier/more efficient way to do it, but you can do
>
> services = []
> for p in Profile.objects.all():
> services += p.ser
There's probably an easier/more efficient way to do it, but you can do
services = []
for p in Profile.objects.all():
services += p.service_set.all()
Todd
On Dec 31, 2007 7:07 PM, ocgstyles <[EMAIL PROTECTED]> wrote:
>
> Hi All,
>
> I'm trying to figure out how to accomplish something using
Hi All,
I'm trying to figure out how to accomplish something using Django's
database API, that I can easily do with SQL. Here's my models:
class Service(models.Model):
name = models.CharField(max_length=50)
class Profile(models.Model):
user = models.ForeignKey(User)
service = models.M
6 matches
Mail list logo