django

Django: How to define a model relationship to achieve the following?:

My app has clients that each have a single billing profile. I'm envisioning my app having a "Client" model with an attribute called "billing_profile" which would reference another model called "BillingProfile". Rather than define "BillingProfile" with a foreign key back to "Client" (ie, "client = models.ForeignKey(Client)"), I was think...

Field.initial in views.py Django?

I read http://docs.djangoproject.com/en/dev/ref/forms/fields/ >>> class CommentForm(forms.Form): ... name = forms.CharField(initial='Your name') ... url = forms.URLField(initial='http://') ... comment = forms.CharField() >>> f = CommentForm(auto_id=False) >>> print f <tr><th>Name:</th><td><input type="text" name="name" value...

Django Forms save_m2m

Hi I have a model which has 2 many to many fields in it. one is a standard m2m field which does not use any through tables whereas the other is a bit more complecated and has a through table. I am using the Django forms.modelform to display and save the forms. The code I have to save the form is if form.is_valid(): f = form....

problem serving static files to sub directories

In the development environment, static files are served properly as long as the url pattern is limited to one directory. Sub directories lose the css. For example the css processes for the template attached to the following url: //localhost:8000/create/ however this: //localhost:8000/edit/2/ will not provide the css even if i...

Django search functionality - bug with search query of length 2

As I am an impressed reader of Stack Overflow I want to ask my first question here. Since I encountered a problem with a snippet and I do not know whether I made a mistake or it's a bug in the code I'm using. I adapted this code for my own site: http://blog.tkbe.org/archive/django-admin-search-functionality/ It works fine and it's rea...

Django: writing a manager to filter query set results

Hello all, I have the following code: class GroupDepartmentManager(models.Manager): def get_query_set(self): return super(GroupDepartmentManager, self).get_query_set().filter(group='1') class Department(models.Model): name = models.CharField(max_length=128) group = models.ForeignKey(Group) def __str__(self): return self.n...

Django Form Models and Editing

Wow, I'm having such a hard time on this. I must be doing something wrong, I'm getting an incredible ammount of queries. So, my models are the following: Player Clan Match (as in game match) MatchMap (the maps played of a match) MatchPlayer (the players of a match) All of them are related via foreign key, no m2m relationship. A player ...

Deploying Django at alwaysdata.com

i new on django i tried this but i cant deploy. how can i do #!/usr/bin/python import sys import os base = os.path.dirname(os.path.abspath(__file__)) + '/..' sys.path.append(base) os.environ['DJANGO_SETTINGS_MODULE'] = 'myfirstapp.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() A...

Django-haystack result filtering using attributes?

Can someone show me an example of how to filter fulltext search results with django-haystack using attributes? I went through the tutorial on their website but am still mot sure on how to use haystack. For instance, let's say I have a class Product: class Product(models.Model): title = models.CharField(max_length=200) descripti...

Python - Idiom to check if string is empty, print default

heya, I'm just wondering, is there a Python idiom to check if a string is empty, and then print a default if it's is? (The context is Django, for the __unicode__(self) function for UserProfile - basically, I want to print the first name and last name, if it exists, and then the username if they don't both exist). Cheers, Victor ...

Django: structuring a complex relationship intended for use with built-in admin site

Hi, I have a fairly complex relationship that I am trying to make work with the Django admin site. I have spent quite some time trying to get this right and it just seems like I am not getting the philosophy behind the Django models. There is a list of Groups. Each Group has multiple departments. There are also Employees. Each Empl...

[Django] How to get latest timestamp in a column?

I have a timestamp column in my t1 table. The format is as: 2009-12-24 06:17:34 There are many entries as such. How do we query from views to get the latest timestamp ...

render_to_response gives TemplateDoesNotExist

I am obtaining the path of template using paymenthtml = os.path.join(os.path.dirname(__file__), 'template\\payment.html') and calling it in another application where paymenthtml gets copied to payment_template return render_to_response(self.payment_template, self.context, RequestContext(self.request)) But I get error Templ...

filter using Q object with dynamic from user?

In my views.py I have a method: #...... def get_filter_result(self, customer_type, tag_selected): list_customer_filter=[] customers_filter = Customer.objects.filter(Q(type__name=customer_type), Q(active=True), Q(tag__id=...

why my extjs combobox is not filled dynamically?

Here is my Extjs onReady function var store = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: '/loginjson.json' }), reader: new Ext.data.JsonReader( {root: '...

django templatetags template , combine {{ }} method call with template tag context variable

hi there, i m trying to make the result of a template tag dependent from another template tag. the use case is the following. i have a headers list which contains all the columns i want to show in a table + the column of the model they are showing +whether they are visible or not. LIST_HEADERS = ( ('Title', 'title', True), ('F...

Django manytomany signals ?

Let's say I have such model class Event(models.Model) users_count = models.IntegerField(default=0) users = models.ManyToManyField(User) How would you recommend to update users_count value if Event add/delete some users ? ...

Best way to add common date_added, date_modified to many models in Django

I am adding date_added and date_modified fields to a bunch of common models in my current project. I am subclassing models.Model and adding the appropriate fields, but I want to add automated save behavior (i.e: evey time anyone calls MyModel.save(), the date_modified field gets updated. I see two approaches: overriding the save() method...

Django JSON Serialization with Mixed Django models and a Dictionary

I can't seem to find a good way to serialize both Django Models and Python dictionaries together, its pretty common for me to return a json response that looks like { "modified":updated_object, "success":true ... some additional data... } Its simple enough to use either simplejson to serialize a dict or Django's serializers.seri...

Django uploading image error

Hello! I'm trying to upload an image using normal form for normal admin for normal model with normal image field. thumb = fields.ThumbnailField(upload_to=make_upload_path, sizes=settings.VIDEO_THUMB_SIZE, blank=True, null=True) But I'm getting an error: Upload a valid image. The file you uploaded was either not an image or a corrupt...