django-models

Django - delete an object without deleting its related objects.

What I mean is I have: class Client(models.Model): some_field = models.CharField() class Ticket(models.Model): client = models.ForeignKey(Client) Tickets are FOREVER in my system, but I want users to be able to delete clients they don't want anymore. Currently it'll delete all the tickets created by the Client. Is this a ba...

django multiple relations to single data model

my example (I know it's not technically correct, it's just an example): class ipAddy(models.Model): network=models.ForeignKey(network) ipAddy=models.IPAddressField(foo) class device(models.Model): hostname=models.CharField(foo) foo=models.CharField(bar) bar=models.CharField(foo) class Meta: abstract = T...

Using django filter() with a querset as args or kwargs

Hello djangoists. How to I make the following possible? models.py class Article(models.Model): #... regions = models.ManyToManyField(Region) elsewhere... regions = Region.objects.all() articles = Article.objects.filter(regions=regions) Currently, the 'articles' retrieved are only from a match with the first region in the ...

How to test Models in Django with Foriegn Keys

I want to make sure I am testing Models/Objects in isolation and not as one huge system. If I have an Order object and it has Foreign Keys to Customers, Payments, OrderItems, etc. and I want to test Order functionality, I need to create fixtures for all of that related data, or create it in code. I think what I really need to be doing i...

Django models and multilingual websites

I have a model that has multiple text properties - title, short and long description etc. I want to have multilanguage site so I need a way to easy by able to add new languages and translations for this field for every item. What is the best way to achieve this? ...

Can i get models field type from a model queryset in Django?

Can i get model field type from a model queryset in Django? For example: a is b model's queryset and the b model has following fields: f:charfield g:foreignkey h:manytomany Is there any way to get field g's type from queryset a? thx. ...

Django Model data incomplete

I have a model with 6 fields, but when I access them using the author field and print the result, it only displays 4 of them, field5 is not shown. The admin shows all fields. My view, model and modelform are below. if request.POST: c1 = Datastore.objects.get(author = request.user) return HttpResponse(c1) class Datastore(models...

django query using and clause

How to use and clause in Django For ex: select Date(timestamp) from userlog where (Date(timestamp) >= "2008-01-02" and Date(timestamp) <= "2009-01-02") and ipaddress != "192.168.2.211"; Django query: userlog.objects.filter(timestamp__range=(startdate,enddate),ipaddress !="192.168.2.211") In the above there is an error ...

Denormalising field in django

I'm finding it difficult to denormalise a field in a django model. I have: class AnswerSet(models.Model): title = models.CharField(max_length=255) num_answers = models.PositiveIntegerField(editable=False, default=0) answers = models.ManyToManyField(Answer, through='AnswerSetAnswer') ... class AnswerSetAnswer(models.Mode...

How to Django models

I am exploring Django with MySQL & have a few things that I wanted to discuss - How can I add an index (on some field)? Can I do it through the Django Model Layer? If I want to migrate some old data into these new DB tables/models, will I have to write some script myself or does Django provide schema to schema mapping tools? If I need...

Password field in Django model

I'm trying to create a model where I can store usernames and passwords for other applications. How can I set a password field in Django so that it is not in plain text in admin? Thanks in advance. ...

Django Models: preserve object identity over foreign-key following.

Django's ORM (version 1.2.3) does not preserve identity when following foreign keys back and forth. This is best explained with an example: class Parent(models.Model): pass class Child(models.Model): parent = models.ForeignKey(Parent) parent = Parents.objects.get(id=1) for child in parent.child_set.all(): print id(child.pa...

Django: Model Design & Best Practice

I need to create an app that fetches the choices for some of the fields from a web service. Those fields are things like Country (single value), State (single value), Interests (Ecology, Biology, Chemistry, etc.) (multiple values), etc. The web service returns for Country looks like: { 'USA':'United States of America', 'GER':'G...

Django auth.models.py change.

I am trying to make a change at the auth.models.py file to force the password hashing function (get_hexdigest()) to not use the salt when passing the sha1. So the change would be: auth.models.py line 33 before: return sha_constructor(salt+raw_password) after: return sha_constructor(raw_password) However, when I make the chang...

Adding model-wide help text to a django model's admin form

In my django app, I would like to be able to add customized help text to the admin change form for some of my models. Note I'm not talking about the field specific help_text attribute that I can set on individual fields. For example, at the top of the change form for My_Model in My_App I'd like to be able to add some HTML that says "Fo...

django ManyToManyField show slug as label

Hi guys, i have a "rare" behavior here, i this model: models.py class Area(models.Model): area = models.CharField(max_length=150,unique=True) slug = models.SlugField(max_length=200) fecha = models.DateTimeField(default=datetime.date.today,editable=False) activa = models.BooleanField(default=True) class Empresa(models.M...

Database Design: ordered many-to-many relationship

In Django, I have the following models: class Pink(models.Model): ... class White(models.Model): ... pinks = models.ManyToManyField(Pink) ... At some point, I needed to define an ordering of Pinks inside a White (in order to have White1.pinks: P1, P2, P3 instead of a random White1.pinks: P2, P3, P1), so I've created ...

Is there a ready-to-use form to display lists of objects in the django forms api?

Is there a form(or any other solution) that allows me to quickly build forms that display lists of models(with filtering, ordering etc) like the django admin site does? ...

Is there a downside to using ".filter().filter().filter()..." in Django?

Are the following two calls resolved to the equivalent SQL query in Django? Chaining multiple calls Model.objects \ .filter(arg1=foo) \ .filter(arg2=bar) \ ... Wrapping all the args together: Model.objects \ .filter(arg1=foo, arg2=bar) I'd like code to be readable (there are MANY more filter calls than I've shown), but only if the...

Django, dynamic apps support.

Hello All, I am about to start a django project, where I need a base deployment, lets say just for admins initially. Later admins can add instances of my main public site. Now, one instance will, obviously be separated by dynamic sub-domains. I need to capture sub-domains from requests, and compute accordingly. It has its own base temp...