Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 17, 2011 17:24:55

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

a chicken and egg - help please?


models are:

from django.db import models
from userprofile.models import Lecturer, UserProfile
from django.contrib.auth.models import User
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django import forms


class Category(models.Model):
name = models.CharField(max_length=50)
lecturer = models.ManyToManyField(Lecturer)
description = models.TextField(null=True, blank=True)
data = models.TextField(help_text='This is the embedded playlist from
SVP', null=True, blank=True)
priority = models.IntegerField(default=50)

def data_chunk(self):
return "%s" % self.data
# data_chunk.allow_tags = True

def __unicode__(self):
return self.name

def get_category(self):
return self.name

class Meta:
verbose_name_plural = "Categories"


class Video(models.Model):
category = models.ManyToManyField(Category)
lecturer = models.ForeignKey(Lecturer)
title = models.CharField(max_length=100)
short_description = models.TextField(null=True, blank=True)
description = models.TextField(null=True, blank=True)
time = models.CharField(max_length=20, help_text='The length, time, of
the video')
is_trailer = models.BooleanField()
is_descriptor = models.BooleanField(help_text='Use this description as
the total lecture description')
meta_title = models.CharField(max_length=100, blank=True)
meta_desc = models.CharField(max_length=250, blank=True)
meta_keywords = models.CharField(max_length=250, blank=True)

def __unicode__(self):
return self.title

class Meta:
verbose_name_plural = "Videos"

problem view is

from video.models import Video, Category
from userprofile.models import Lecturer, UserProfile
from django.shortcuts import render_to_response
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User

def cat_view(request, id):
cat = Category.objects.get(pk=id)
vid = Video.objects.select_related().all().filter(category =
cat).filter(is_trailer=False).filter(is_descriptor=True)
return render_to_response('video/list.html', {'cat': cat, 'vid': vid, },
context_instance=RequestContext(request))

The problem is I can get at the foreign key lecturer with the select_related
but I actually want to order_by the query set vid by a function that I can
only get at within the individual video as in
name = v.lecturer.get_surname()

additional to this the categories per video need to be detailed as well
(category the video belongs to is a ManyToMany)

so my question is how to I order the query set by a foreign key that has a
function to get the surname and also output on the template all the
categories that the video belongs to?



--
View this message in context:http://old.nabble.com/a-chicken-and-egg---help-please--tp30676218p30676218.htmlSent from the django-users mailing list archive at Nabble.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-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 17, 2011 18:18:08

Vovk D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

a chicken and egg - help please?


>
> additional to this the categories per video need to be detailed as well
> (category the video belongs to is a ManyToMany)
>

If i understand you correctly then If you want some aditional information
to be
putted on the ManyToMany relationship then u need to use "through" parametr
and one more table.
look in docs.

>
> so my question is how to I order the query set by a foreign key that has a
> function to get the surname and also output on the template all the
> categories that the video belongs to?
>
>
>
To get all categories of the Video item u can do:
video.category.all()

About your wish to use method of get_surname to sort queryst - i think it's
not possible to do in this ORM.(well, i'll be happy if im wrong)
But you can sort queryset after you get it or you could subclass
models.query.QuerySet to add you own functionality like
Item.objects.filter(...).order_by_surname(item.get_surname()) or smth like
this
--
*Vovk Donets*
python/django developer

skype: suunbeeam
icq: 232490857
mail: donets.vladi...@gmail.com
www: vovk.org.ru

--
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
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 18, 2011 12:21:30

David D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

a chicken and egg - help please?


On 18/01/11 07:26, Jani Tiainen wrote:

> It's just not possible to run any arbitrary Python code
> in a database.

Well, technically there's a pl/python module for postgresql. ;-)
(doesn't really help, I'm just saying)http://www.postgresql.org/docs/9.0/interactive/plpython.html--
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
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 19th of October
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