django-models

How retrieve all comments of all posts

I have a Blog model, a Post model and a Comment model: class Blog(models.Model): title = models.CharField(_('name'), max_length=80) creator = models.ForeignKey(User, related_name="created_pages") created = models.DateTimeField(_('created'), default=datetime.now) description = models.TextField(_('description'), n...

Django Managers

I have the following models code : from django.db import models from categories.models import Category class MusicManager(models.Manager): def get_query_set(self): return super(MusicManager, self).get_query_set().filter(category='Music') def count_music(self): return self.all().count() class SportManager(models...

Django-reversion and south compatibility

Does django-reversion work well with south migrations? Are django-reversion and south compatible? Current versions: - reversion - 1.2.1 - south - 0.7.1 ...

Help a Python newbie with a Django model inheritance problem

I'm working on my first real Django project after years of PHP programming, and I am running into a problem with my models. First, I noticed that I was copying and pasting code between the models, and being a diligent OO programmer I decided to make a parent class that the other models could inherit from: class Common(model.Model): ...

django objects.all() method issue

after I saved one item using MyModelClass.save() method of django in one view/page , at another view I use MyModelClass.objects.all() to list all items in MyModelClass but the newly added one always is missing at the new page. i am using django 1.1 i am using mysql middleware setting MIDDLEWARE_CLASSES = ( 'django.middleware.common...

Django get() query not working

this_category = Category.objects.get(name=cat_name) gives error: get() takes exactly 2 non-keyword arguments (1 given) I am using the appengine helper, so maybe that is causing problems. Category is my model. Category.objects.all() works fine. Filter is also similarily not working. Thanks, ...

How to save links with tags and parameters in TextField

I have this simple Post model: class Post(models.Model): title = models.CharField(_('title'), max_length=60, blank=True, null=True) body = models.TextField(_('body')) blog = models.ForeignKey(Blog, related_name="posts") user = models.ForeignKey(User) I want that when I insert in the form the links, then these lin...

Could I use urlize filter in this way ?

Could I use urlize filter in this way? : from django.utils.html import urlize def save(self, force_insert=False, force_update=False): self.body = urlize(self.body) super(Post, self).save(force_insert, force_update) body is a TextField. ...

How can join two django querysets in one?

I need order a Queryset by date in desc order, but i need put in the end the objects at the end, I do this: qs1 = Model.objects.exclude(date=None).order_by('-date') qs2 = Model.objects.filter(date=None).order_by('-date') and my list is: l = list(qs1)+list(qs2) There is a more efficiently way for this? ...

Django get old url

In django views,From the request how would we know from which page this view was called def password_change(request): if request.method == 'POST': u=request.user u.set_password(request.POST.get('new_password')) u.save() post_change_redirect= //Need old link here return HttpResponseRedirect(post_change_...

Odd behavior in Django Form (readonly field/widget)

I'm having a problem with a test app I'm writing to verify some Django functionality. The test app is a small "grade book" application that is currently using Alex Gaynor's readonly field functionality http://lazypython.blogspot.com/2008/12/building-read-only-field-in-django.html There are 2 problems which may be related. First, when ...

Manditory read-only fields in django

I'm writing a test "grade book" application. The models.py file is shown below. class Student(models.Model): name = models.CharField(max_length=50) parent = models.CharField(max_length=50) def __unicode__(self): return self.name class Grade(models.Model): studentId = models.ForeignKey(Student) finalGrade =...

Doubt about django model API

Hello guys! So, here is what I want to do. I have a model Staff, that has a foreign key to the User model. I also have a model Match that has a foreign key to the User model. I want to select how much Matches every Staff has. I don't know how to do that, so far I only got it working for the User model. From Staff, it will not allow to a...

Django unique_together error and validation

class Votes(models.Model): field1 = models.ForeignKey(Blah1) field2 = models.ForeignKey(Blah2) class Meta: unique_together = (("field1","field2"),) I am using this code as one of my models. Now i wanted to know two things: 1. It doesn't show any error and it saved an entry which wasn't unique together; S...

Django User model, adding function

Hello, I want to add a new function to the default User model of Django for retrieveing a related list of Model type. Such Foo model: class Foo(models.Model): owner = models.ForeignKey(User, related_name="owner") likes = models.ForeignKey(User, related_name="likes") ........ #at some view user = request.user foos...

Django forms "not" using forms from models

I have a form generated from various models and the various values filled go and sit in some other table. Hence, in this case I haven't used the inbuilt Django forms(i.e. I am not creating forms from models ). Now the data which is posted from the self made form is handled by view1 which should clean the data accordingly. How do I go...

CakePHP: How to limit number of records from associated model

In a simple CakePHP model where User hasMany Item (and Item belongsTo User)- Suppose 50 users, have each 10 items. How can I find() only 5 users, each with the latest 5 items he has? When I impose a limit in the find, it only limits the number of users, not the number of associated Items. Thanks! ...

CharField values disappearing after save (readonly field)

I'm implementing simple "grade book" application where the teacher would be able to update the grades w/o being allowed to change the students' names (at least not on the update grade page). To do this I'm using one of the read-only tricks, the simplest one. The problem is that after the SUBMIT the view is re-displayed with 'blank' value...

What kind of data do I pass into a Django Model.save() method?

Lets say that we are getting POSTed a form like this in Django: rate=10 items= [23,12,31,52,83,34] The items are primary keys of an Item model. I have a bunch of business logic that will run and create more items based on this data, the results of some db lookups, and some business logic. I want to put that logic into a save signal or...

Can I add other tables in my db ?

Can I add other tables in the database created by django ? It is for my PHP application. ...