I'm overriding a django model save() method. Within the override I'm calling another method of the same class and instance which calculates one of the instance's fields based on other fields of the same instance.
class MyClass(models.Model):
field1 = models.FloatField()
field2 = models.FloatField()
field3 = models.FloatField()
def…
So I have a Django app that processes test results, and I'm trying to find the median score for a certain assessment. I would think that this would work:
e = Exam.objects.all()
total = e.count()
median = int(round(total / 2))
median_exam = Exam.objects.filter(assessment=assessment.id).order_by('score')[median:1]
median_score = median_exam.score
…
Using the voting buttons in Outlook 2007, apparently users can submit votes as many times as they like. (I have just now verified this behaviour.) Is there a way to restrict the uses to just one vote each? I've found a script online which claims to do this, but there's no way I can use a script like that across our company. I'm hoping it's…
How would I be able to use the Drupal Fivestar voting module for voting on photos in a gallery without each photo being a separate node. I've used the Fivestar module for voting on seperate nodes, but making each photo in a gallery a node doeasn't seem logical.
thanks
I'm trying to add the facebook connect feature to my site, I decided to use django socialregistration.All are setup including pyfacebook, here is my source code.
settings.py
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
…
I'm writing a test "grade book" application. The models.py file is shown below.
class Student(models.Model):
name = models.CharField(max_length=50)
parent = models.CharField(max_length=50)
def __unicode__(self):
return self.name
class Grade(models.Model):
studentId =…
I'm fairly new to both Django and Python. This is my first time using forms and upload files with django. I can get the uploads and saves to the database to work fine but it fails to valid email or check if the users selected a file to upload. I've spent a lot of time reading documentation…
I've got a view in Django that uses memcached to cache data for the more highly trafficked views that rely on a relatively static set of data. The key word is relatively: I need invalidate the memcached key for that particular URL's data when it's changed in the database. To be as clear as…
I've got two django models (simplified):
class Product(models.Model):
name = models.TextField()
price = models.IntegerField()
class Invoice(models.Model):
company = models.TextField()
customer = models.TextField()
products = models.ManyToManyField(Product)
I would…
Here's another question about Django.
I have this code:
views.py
cursor = connections['cdr'].cursor()
calls = cursor.execute("SELECT * FROM cdr where calldate > '%s'" %(start_date))
result = [SQLRow(cursor, r) for r in cursor.fetchall()]
return render_to_response("cdr_user.html",
…
I've got a ModelForm based on a Picture.
class Picture(models.Model):
name = models.CharField(max_length=100)
pub_date = models.DateTimeField('date published')
tags = models.ManyToManyField('Tag', blank=True)
content = models.ImageField(upload_to='instaton')
def…
All,
How Can we increment a value like the following in django templates,
{{ flag =0 }}
{% for op in options %}
{{op.choices}}<input type="radio" name="template" id="template" value="template{{flag++}}"/>
{% endfor %}
thanks..
In my django views i have the following
def create(request):
query=header.objects.filter(id=a)[0]
a=query.criteria_set.all()
logging.debug(a.details)
I get an error saying 'QuerySet' object has no attribute 'details' in the debug statement
.What is this error and what…
How to pass two paramters in urls in django
<script>
url=/toolbox/display/" + id + "2";
window.location=url;
</script>
Also how is this handeled in urls.py
(r'^display/(?P<rid>\d+)/(?P<param>\d+)/$', 'table_display'),
In…
I have a form generated from various models and the various values filled go and sit in some other table. Hence, in this case I haven't used the inbuilt Django forms(i.e. I am not creating forms from models ).
Now the data which is posted from the self made form is…
I'm modeling a simple movie database using Django.
models.py defines a base model Person. I extend Person into Actor and Director, which works as I imagined. Persons must be unique.
When (in the Admin) I create an instance of Actor, and this person is also a…
In django views
def add(request):
dict{}
co_data = optarr
dict.update({'co_data' : co_data})
logging.debug(co_data)
return render_to_response('scheme/create.html',context_instance=RequestContext(request,{'dict': dict}))
And data has the…
In Django's ModelAdmin I need to display forms customized according to the permissions an user has. Is there a way of getting the current user object into the form class, so that i can customize the form in its __init__ method?
I think saving the current…
Is there a difference between filter and exclude in django? If I have
self.get_query_set().filter(modelField=x)
and I want to add another criteria, is there a meaningful difference between to following two lines of code?
…
Hello,
I want to add a new function to the default User model of Django for retrieveing a related list of Model type.
Such Foo model:
class Foo(models.Model):
owner = models.ForeignKey(User, related_name="owner")
…
Hello,
I'm trying to store a number in django that looks like this:
000001
My problem is that if I type this inside an IntegerField it gets converted to "1" without the leading zeros. I've tried also with a…
I have these 2 models:
genre = (
('D', 'Dramatic'),
('T', 'Thriller'),
('L', 'Love'),
)
class Book(models.Model):
title = models.CharField(max_length=100)
genre =…
I have a many to many field, which I'm displaying in the django admin panel. When I add multiple items, they all come up as "ASGGroup object" in the display selector. Instead, I want…