django-models

Django syncdb error

/mysite/project4 class notes(models.Model): created_by = models.ForeignKey(User) detail = models.ForeignKey(Details) Details and User are in the same module i.e,/mysite/project1 In project1 models i have defined class User(): ...... class Details(): ...... When DB i synced there is an error saying Error:...

Force sending a user to custom QuerySet.

I'm trying to secure an application so that users can only see objects which are assigned to them. I've got a custom QuerySet which works for this, but I'm trying to find a way to force the use of this additional functionality. Here is my Model: class Inquiry(models.Model): ts = models.DateTimeField(auto_now_add=True) assig...

Can django's auth_user.username be varchar(75)? How could that be done?

Is there anything wrong with running alter table on auth_user to make username be varchar(75) so it can fit an email? What does that break if anything? If you were to change auth_user.username to be varchar(75) where would you need to modify django? Is it simply a matter of changing 30 to 75 in the source code?: username = models.CharF...

Django project models.py versus app models.py

I am learning Django and I am trying to understand the use of models.py in the project versus the application. It seems from the tutorial examples that I include a model definition in the app, but when I went to apply that knowledge to my own existing database I got stuck. I took a database that I use (a copy of course) and generated t...

working on lists in python

'm trying to make a small modification to django lfs project, that will allow me to deactivate products with no stocks. Unfortunatelly I'm just beginning to learn python, so I have big trouble with its syntax. That's what I'm trying to do. I'm using method 'is_variant' returning tru if my product is a sub type. If it is a variant I'm tur...

django models : How to have variable number of foreign keys in a model ?

For instance, Model Resume contains variable number of Model Project 's, What should be my models and relationships between them to achieve this ? Thanks in advance. ...

django: results in in_bulk style without IDs

in django 1.1.1, Place.objects.in_bulk() does not work and Place.objects.in_bulk(range(1, 100)) works and returns a dictionary of Ints to Places with indexes - primary keys. How to avoid using range in this situation (and avoid using a special query for ids, I just want to get all objects in this dictionary format) >>> Place.objects.in_...

Getting weird python error when I run a simple django script in Eclipse, not happening in console

I am running a basic script that sets up the django environment by itself, to enable me to test the ORM features of django without having to implement web pages. The script then imports one of the types defined in my models. This error doesn't happen when I run this script from iPython, only from eclipse. Simply doing this import causes ...

In Django, how to create tables from an SQL file when syncdb is run

Hi, How do I make syncdb execute SQL queries (for table creation) defined by me, rather then generating tables automatically. I'm looking for this solution as some particular models in my app represent SQL-table-views for a legacy-database table. So, I've created their SQL-views in my django-DB like this: CREATE VIEW legacy_series AS S...

Copying contents of a model

If there exists an old data of a model say , query=Emp.objects.filter(pk=profile.id) Is there a easier way to copy the same values into the same model again.. Now that the id will be different so.. I have this requirement. Thanks.. ...

Maintaining content type pk integrity in a Django deployment

When you run syncdb in Django, the primary keys of the content types will be recomputed. If I create new models, the next time I run syncdb, the primary keys of the content types will be different. If I have an application running in production, how can I update the database with the new models and keep the integrity of content type pk...

Decrease DB requests number from Django templates

I publish discount offers for my city. Offer models are passed to template ( ~15 offers per page). Every offer has lot of items(every item has FK to it's offer), thus i have to make huge number of DB request from template. {% for item in offer.1 %} {{item.descr}} ...

Django admin - limiting access to objects based on the user logged in

Hi, I'm working on creating a simple website for an exhibition. It's intended to use django with django CMS as much as possible - so Django admin site will be used. Now I want to limit user's access to objects they can view/modify/delete. There's going to be an Admin user, who can do all that admin can in django. But there are going t...

Django model manager didn't work with related object when I do aggregated query

Hi, all. I'm having trouble doing an aggregation query on a many-to-many related field. Here are my models: class SortedTagManager(models.Manager): use_for_related_fields = True def get_query_set(self): orig_query_set = super(SortedTagManager, self).get_query_set() # FIXME `used` is wrongly counted ret...

django models: how to select only objects which aren't belong to the inherited class?

Hello! I have two models in my Django 1.1.1 application: class UserRequest(models.Model): # blah blah class JournalistRequest(UserRequest): # blah blah So, JournalistRequest is a special type of UserRequest, and all JournalistRequests are still common UserRequests with special fields. JournalistRequest.objects.all() returns a...

Populating Models from other Models in Django?

This is somewhat related to the question posed in this question but I'm trying to do this with an abstract base class. For the purposes of this example lets use these models: class Comic(models.Model): name = models.CharField(max_length=20) desc = models.CharField(max_length=100) volume = models.IntegerField() ... <50 o...

Django: Display UTC timestamp field as DateField inside form

My model has a field of integer type representing timestamp in UTC. I would like that field to be displayed as DateField inside my form. I'm using admin interface, i.e I have MyAdmin class inheriting from admin.ModelAdmin, which get passed into admin.site.register(...) function. ...

Django Querysets -- need a less expensive way to do this..

Hi all, I have a problem with some code and I believe it is because of the expense of the queryset. I am looking for a much less expensive (in terms of time) way to to this.. log.info("Getting Users") employees = Employee.objects.filter(is_active = True) log.info("Have Users") if opt.supervisor: if opt.hierarchical: peopl...

Is django orm & templates thread safe?

I'm using django orm and templates to create a background service that is ran as management command. Do you know if django is thread safe? I'd like to use threads to speed up processing. The processing is blocked by I/O not CPU so I don't care about performance hit caused by GIL. ...

Complex Django filter question

Lets say I have this class (simplified): class Tag (...): children = models.ManyToManyField(null=True, symmetrical=False) Now I already implemented the functions get_parents, get_all_ancestors. Is there a nice pythonic way to just the top level tags? If I had designed my Tags differently (to point to the parents instead) I would j...