django

Django: return decimal instead of strange object

Hi, I have a model with a decimal field. The output of: def special_method(self): return MyClass.objects.filter(product=self).order_by('-date_active')[0:1] on this model is: [<MyClass: 10.00>] ... and I have defined the following method on MyClass: def __str__(self): return str(self.rate) This may be a silly question b...

django user relationship

Using django, say I have model classes A and B, representing different types of Companies. Each Company may have multiple Users associated with it. Obviously I'd like to use django's User model, to get the login, etc. goodness. How would I go about doing that? Would I add a UserProfile that has two foreign keys, one to A and one to B...

Control Query set in Django (filter,object Q)?

Base On URL querydict = {customer_type:val1,tag:[], city:[],last_contact:valdate} show/?customer_type=All&tag=2,3&city=3&last_contact=29/12/2009 I am going to filter by made the method: def get_filter_result(customer_type, tag_selected, city_selected, last_contact_filled): if customer_type=has value: I filter by this ...

Condition Query set in Django (filter,object Q)?

My Url for pass to method: customer_type=All&tag=2,3&city=8,9&last_contact= is came from querydict = {customer_type:val1,tag:[], city:[],last_contact:valdate} def get_filter_result(self, customer_type='', tag_selected='', city_selected='', last_contact_filled=''): if customer_type != '': if customer_t...

Loading SQL dump before running Django tests

I have a fairly complex Django project which makes it hard/impossible to use fixtures for loading data. What I would like to do is to load a database dump from the production database server after all tables has bene created by the testrunner and before the actual tests start running. I've tried various "magic" in MyTestCase.setUp(), b...

MySQLdb problem with Django and PyDev

Hi all, I built my project with Django in Pydev. Every thing is working well. Now I configured PyDev to debug the project by adding runserver 8001--noreload When I sent the Database engin to sqlite3 every thing is ok and I can debug the project. When I put the database engin to MySQL (my real DB) and try to debug, I get : django.core.ex...

Django: Filtering on the related object, removing duplicates from the result

Given the following models: class Blog(models.Model): name = models.CharField() class Entry(models.Model): blog = models.ForeignKey(Blog) content = models.CharField() I am looking to pass the following to a template: blogs = Blog.objects.filter(entry__content__contains = 'foo') result = [(blog, blog.entry_set.filter(con...

django query question

Hello Assume I have such simple model: class Foo(models.Model): name = models.CharField(max_length=25) b_date = models.DateField() Now assume that my query result from Foo.objects.all() , I retrieve something like this: [ {'name': 'zed', 'b_date': '2009-12-23'}, {'name': 'amy', 'b_date': '2009-12-6'}, {'name': 'j...

Python - reading checkboxes

Hello. I have a few checkboxes with common name and individual variables (ID). How can I in python read them as list? Now I'm using checkbox= request.POST["common_name"] It isn't work properly, checkbox variable store only the last checked box instead of any list or something. ...

django pluralization functional.__proxy__object instead of verbose_name

Hi, I`m trying to create a message which uses some kind of pluralization. The message look like this and depends on the number of deleted objects. Successfully deleted [number of objects] Contact(s) Thus output can be: Successfully deleted 1 Contact Successfully deleted 5 Contacts To achieve this task i followed the pluralization ...

Django template question

Hello How can I achieve this using the Django template system: Say I have 2 variable passed to the template system: days=[1,2,3,4,5] items=[ {name:"apple,day:3},{name:"orange,day:5} ] I want to have such output as a table: 1 2 3 4 5 apple n n y n n orange n n n n y As you can notice, gi...

django redirect to calling view after processing function

Hi, I have written a function having the following signature: def action_handler(request, model): This action_handler is used from different views and handles the actions for this views. One example is deleting objects. In this example the user selectes some objects, selects the delete action and then the user is presented a page to ...

TimeField question regarding blank/null

I have a model (and model form based on it) that has several time fields. I want these fields to be optional such that the user may leave some empty. My problem is that I continue to receive "Column 'mechreturn_tm' cannot be null" errors when I attempt to save an instance where one or more of these fields are blank. I've used the followi...

Django - filtering on foreign key properties

I'm trying to filter a table in django based on the value of a particular field of a foreign key. For example I have two models - Project and Asset, Project has a "name" field and each asset has a ForiegnKey(Project) field. I'd like to filter my asset list based on the name of the associated project. Currently I am performing two queri...

Django, grouping query items

Hello, say I have such model: class Foo(models.Model): name = models.CharField("name",max_length=25) type = models.IntegerField("type number") after doing some query like Foo.objects.filter(), I want to group the query result as such: [ [{"name":"jb","type:"whiskey"},{"name":"jack daniels","type:"whiskey"}], [{"name":"absolute","...

Django form from related model

You have models: class Order(Model): date = DateField(editable = False, auto_now_add=True) status = CharField(max_length = 1, choices = STATUS, default = 'N') profile = ForeignKey(Profile, related_name = 'orders', blank = True, null = True) shipping = ForeignKey(Shipping, related_name = 'orders', blank = True, null = True) address ...

Spam Filtering Forms Without Akismet

I'm curious if anyone out there knows of something perhaps like Akismet, but where content doesn't have to go off to a 3rd party server. In a situation with critically sensitive data (patient records for instance) I wouldn't necessarily want that information sent off to another server I don't have control over. I really like Akismet, it ...

What tools can I use for Django Testing Automation?

I'm looking into automating a test runner which would do the following things daily (or hourly or whenever I want basically): Pull the latest code from a git repository. Run the Django test suite or something like Nose. Run Selenium tests. Give Pass/Fail and coverage statistics via a web interface. Email developers in the case of failu...

django change form field in .html template output

Hi, I create a form based on a model , like seen below: class ContactSelectionForm(forms.ModelForm): contacts = ManyToManyByLetter(Contact, field_name="first_name") class Meta: model = ContactSelection exclude = ('created_by',) When I process this view I see at the .html output a field labeled with "Contact"...

django many2many field make not required

Hi, I created a form based on a model. The model has a many2many field. I defined the field like this: contacts = models.ManyToManyField(Contact, blank=True, null=True) I`m wondering now why the generated form says that this field cannot be blank. I always get the error message "This field is required.", when i do not select a contac...