in my views,
if i import an itertools module:
from itertools import chain
and i chain some objects with it:
franktags = Frank.objects.order_by('date_added').reverse().filter(topic__exact='art')
amytags = Amy.objects.order_by('date_added').reverse().filter(topic__exact='art')
timtags = Tim.objects.order_by('date_added').reverse().fi...
The Django widthratio tag takes three arguments - the top and bottom of a ratio, and a constant value.
If the ratio is greater than one, then the rendered result will be greater than the constant. For example, if your first two numbers are 6 and 3 and your constant is 100, then the rendered number would be 200, not 100.
I'm wondering ...
in my django view, if i import operator, and use the following code:
multitags = sorted(multitags, key=operator.attrgetter('date_added'))
is there an easy way to reverse the order – such that i get the dates in descending order
(today at top; last week underneath)?
...
I have a formset which has a field "Teams" which should be limited to the teams the current user belongs to.
def edit_scrapbook(request):
u=request.user
ScrapbookAjaxForm = modelformset_factory(Scrapbook, fields=
('description','status','team'))
choices=False
for t in u.team_set.all():
if choices:
...
I'm following the Django tutorial and got stuck with an error at part 4 of the tutorial. I got to the part where I'm writing the vote view, which uses reverse to redirect to another view. For some reason, reverse fails with the following exception:
import() argument 1 must be string, not instancemethod
Currently my project's urls.p...
I have a Django form that uses a different number of fields based on the year/month. So I create the fields in the form like this:
for entry in entry_list:
self.fields[entry] = forms.DecimalField([stuffhere])
but now I don't know how to get the submitted data from the form.
Normally I would do something like:
form.cleaned_data["...
I just started to use django. I came across forms and I need to know which one is the better way to validate a forms. Would it be using django forms or should we use javascript or some client side scripting language to do it?
...
I have a model with a field that is required but not entered by the user and i have a hard time saving the model without errors. My model definition looks like this:
class Goal(db.Model):
author = db.UserProperty(required=True)
description = db.StringProperty(multiline=True, required=True)
active = db.BooleanProperty(default=True)...
hi i am creating a mashup in django and google maps and i am wondering if there is a way of clustering markers on the server side using django/python.
...
Hi, I have a problem with serialization of Django inherited models. For example
class Animal(models.Model):
color = models.CharField(max_length=50)
class Dog(Animal):
name = models.CharField(max_length=50)
...
# now I want to serialize Dog model with Animal inherited fields obviously included
print serializers.serialize('xml',...
I have a PDF document that represents a print form that is normally filled out by hand.
I want to to programatically populate certain text fields in the document (it is not a PDF form, just a plain PDF document) and fill it out with data specific to each user of the site.
I want the end form to look like it was passed through a typew...
Is there an easy way to count the lines of code you have written for your django project?
Edit: The shell stuff is cool, but how about on Windows?
...
I haven't been using Django too long, but I'm about to start a pretty hefty-sized project. I'm always nervous using fairly new frameworks (new to me) on large projects because I've been burned before. However, I'm pretty confident in Django...this will finally be the project that makes me leap from my home-grown PHP framework to a popula...
Hello,
I am trying to retrieve the latest 5 posts (by post time)
In the views.py, if I try blog_post_list = blogPosts.objects.all()[:5] It retreives the first 5 elements of the blogPosts objects, how can I reverse this to retreive the latest ones?
Cheers
...
Is there a simple way to make Django render {{myform.name}} as
John Smith
instead of
<input id="id_name" name="name" value="John Smith" />
inside <form> tags? Or am I going about this the wrong way?
...
I'm trying to store the user's ID in the session using django.contrib.auth.login . But it is not working not as expected.
I'm getting error login() takes exactly 1 argument (2 given)
With login(user) I'm getting AttributeError at /login/ User' object has no attribute 'method'
I'm using slightly modifyed example form http://docs.django...
I have a form where a couple of fields are coming out as required when I don't want them too. Here is the form from models.py
class CircuitForm(ModelForm):
class Meta:
model = Circuit
exclude = ('lastPaged',)
def __init__(self, *args, **kwargs):
super(CircuitForm, self).__init__(*args, **kwargs)
self.fields['...
Hi all,
I was going through the django-sphinx documentation, and it looks like it allows you to filter search results using attributes,
queryset = MyModel.search.query('query')
results1 = queryset.order_by('@weight', '@id', 'my_attribute')
results2 = queryset.filter(my_attribute=5)
results3 = queryset.filter(my_other_attribute=[5, 3,4]...
I've serialized my django model:
serializers.serialize(MyModel.objects.filter(color="Red"))
and got this output:
<object model="example.example" pk="133">
<field name="name" type="CharField">John Smith</field>
<field name="color" type="CharField">Red</field>
... #more fields
</object>
So you can see I have pk="133":
An...
I have to insert 8000+ records into a SQLite database using Django's ORM. This operation needs to be run as a cronjob about once per minute. At the moment I'm using a for loop to iterate through all the items and then insert them one by one.
Example:
for item in items:
entry = Entry(a1=item.a1, a2=item.a2)
entry.save()
What is...