django-models

Filter ForeignKey by Boolean value in django

I have these models: class Client(models.Model): is_provider = models.BooleanField() class Billing(models.Model): client = models.ForeignKey(Client) I want to limit the choices of ForeignKey to show only the clients with is_provider=True. Is there something like: limit_choices_to = {'is_provider': True} Or anything I can u...

django mulitidb

Hi i am using django 1.2 .I my case i have few models which are present in one db and others on second db.I have changed my settings.py file with the two database details But when i run the server it says relation not exist. How can i tell that for this model refer 'a' database and for others refer 'b' database. #models.py ### this c...

Django models : Inverted index on timestamp with query for 'n' latest rows

I have the datetime filled with auto_now=True Database is mysql. Range queries won't work for me directly. Is there any one liner for this? For simplicity, how can I get 10 rows with highest values for a field(let it be Integerfield) ? ...

How to print mysql statements executed / to be executed on a statement in django ?

I want want to examine what django does with databse when I execute some statement with a django model For instance Group.members.all() with manage.py shell. Is there any way of doing this? ...

overwrite a model entry

hi can anybody gimme any help about how to overwrite a model entry. i have latitude, longitude, and status fields in my model. once i save the data i cant update or change it from my custom template. how to update or overwrite these fields. this is my views.py def status_change(request): if request.method == "POST": rform = re...

django model -- relationships between inherited models?

I'm working on a server / datacenter inventory management tool. I have a class to define a default "device", which is then used to express custom devices (linux servers, windows servers, routers, switches, etc.) I also have data models set up to express IP addresses within a network. My question is, what would be the best way to expre...

How to provide SQL initial data when app label is used?

From the documentation: Django provides a hook for passing the database arbitrary SQL that's executed just after the CREATE TABLE statements when you run syncdb. You can use this hook to populate default records, or you could also create SQL functions, views, triggers, etc. The hook is simple: Django just looks for a file called...

Uploading file, how validate the kind of file fom django Admin?

Hi guys, im trying to upload videos from django admin, but i cant see how validate upload video files and nothing more. Any idea? Thanks Sorry with my English ...

Can a django model have two abstract classes?

I have this models: class BillHeader(models.Model): billno = models.IntegerField(primary_key=True, blank=True) class BillData(models.Model): price = models.DecimalField(_('Price'), max_digits=12, decimal_places=2) amount = models.DecimalField(_('Amount'), max_digits=6, decimal_places=2) [... rest of the model ...] ...

approaching django model fields through a field name mapping

Hi Guys, Django newbie here, I have several types of models, in each of them the fields have different names (e.g. first_name, forename, prenom) and I want each of the models to contain a mapping so that I can easily approach each of the fields using one conventional name (e.g. first_name for all of the field names). what's a good way o...

How do I get the class of a ManyToMany field in django models?

Hi Django newbie here, I have some fields in a model that are ManyToMany, I want the ManyToMany class itself, when I only have the field name. Is there any way I can retrieve it? ...

Django inline formset with child of a child

Heya! I have three models: Variable, which has Group as a foreign key Group, which has Set as a foreign key Set I want to create a form that lets user create a new Set based on existing Set. Only things that user is able to modify are the Set name and Variable values. This has given me an idea of using inlineformset_factory to acce...

Select all photos from each Album (Django)

I need some help (sorry for my poor english). I 'm trying to get all photos from each album. I don't know how to make the query. I need this data (and order the photos by atribute "order" it will fantastic). House1-title photo1: descritpion photo2: descritpion photo3: descritpion House2-title photo1: descritpion photo2: descritpi...

user_id is not unique

i have a this thing in my views,py def status_change(request): if request.method == "POST": rform = registerForm(data = request.POST) if rform.is_valid(): register = rform.save(commit=False) register.user = request.user register.save() return render_to_response('home.html') else: r...

How to add a LogEntry for all other staff Users in django?

i have a LogEntry in django admin for superadministrator users, but, now i need a LogEntry for the other "staff" users, it's this possible? Thanks folks! ...

Django custom field - automatically add COLLATE to query

Hello, I'm trying to create a custom field which would automatically add COLLATE information into the WHERE part of SQL query: class IgnoreDiacriticsField(models.TextField): def get_prep_lookup(self, lookup_type, value): if lookup_type == 'exact': return ' "' + self.get_prep_value(value) + '" COLLATE utf8_genera...

Mathematical Operations on Django Annotations.

I have a Django model that defines a TimeSlot. Each TimeSlot can hold a certain number of users (TimeSlot.spots). Each TimeSlot also has a certain number of users already held in it (a many to many field, TimeSlot.participants. When I pass to the template that displays the available TimeSlots to the user, I annotate with TimeSlot.objec...

Django: ImageField disable image deletion

Greetings Having an ImageField object in my Foo model as such: class Foo(models.Model): name = models.CharField(max_length=50) photo = models.ImageField(upload_to='foobar', blank=True, null=True) I want Foo to disable to delete the uploaded photo once a Foo object is deleted and a specific . How can I do this? Ie: If self.na...

Iterating through model fields - Django

Hi folks, I'm trying to iterate through fields as they are written down within my model: currently I'm using this: def attrs(self): for attr, value in self.__dict__.iteritems(): yield attr, value but the order seems pretty much random :( Any ideas? ...

django permission issue

Hi Everyone I m dealing with some serious issue in django-admin.I have created models with app_label in class Meta But when i tried to create a group for alloting specific permissions I cant find them in my selection list.But if i remove app_label from my model I can see the model in my permission list.But I cant go without app_label, s...