What I would like to achive is:
I go to admin site, apply some filters to the list of objects
I click and object edit, edit, edit, hit 'Save'
Site takes me to the list of objects... unfiltered. I'd like to have the filter from step 1 remembered and applied.
Is there an easy way to do it?
i have a class named cv,and a class named university, and each user that completes his cv, should choose a University he studyes at.
My problem is: one student can study at one or 2 or three universities, or may be a user that is not student.
I need to take this data into a form, and i use ModelForm. The data from the Cv class, and from the University class in the same form, and the user can add one or more universities, or no university. (in the same form)
How should i do it? Should i use ModelForm? if i have a foreign key in the CV class, and the user is not a student (so he is at zero universities), i may get an referencial integrity error.
thanks a lot
I am trying to download a CSV file using HttpResponse to make sure that the browser treats it as an attachment. I follow the instructions provided here but my browser does not prompt a "Save As" dialog. I cannot figure out what is wrong with my function. All help is appreciated.
dev savefile(request):
try:
myfile = request.GET['filename']
filepath = settings.MEDIA_ROOT + 'results/'
destpath = os.path.join(filepath, myfile)
response = HttpResponse(FileWrapper(file(destpath)), mimetype='text/csv' )
response['Content-Disposition'] = 'attachment; filename="%s"' %(myfile)
return response
except Exception, err:
errmsg = "%s"%(err)
return HttpResponse(errmsg)
Happy Pat's day!
I'm not sure why, but this condition will never evaluate True for me. I'm feeding it datetime.today() in the urls file. Am I missing something?
Template:
{% load humaize %}
{{ entry.date|naturalday }} {# Evals to "today" #}
{% ifequal entry.date|naturalday "today" %}
True
{{ entry.date|date:"fA"|lower }} {{ entry.date|naturalday|title }}
{% else %}
False
{{ entry.date|naturalday|title }}
{% endifequal %}
I want to give default value to a textarea. The code is something like this:
<textarea>{{userSetting.list | join:"NEWLINE"}}</textarea>
where userSetting.list is a string list, each item of whom is expected to show in one line.
textarea takes the content between the tags as the default value, preserving its line breaks and not interpreting any HTML tags (which means <br>,\n won't work).
I have found a solution: {{userSetting.list | join:" " | wordwrap:0}} (there is no whitespace in the list). But obviously it is NOT a good one. Any help would be appreciated.
Is there a way to test the html from the response of:
response = self.client.get('/user/login/')
I want a detailed check like input ids, and other attributes. Also, how about sessions that has been set? is it possible to check their values in the test?
Hi, I'm trying to display a form on a template, but I get a fantastic error :
Caught AttributeError while rendering: 'WSGIRequest' object has no attribute 'get'
The error is in this line : {% for field in form.visible_fields %}
My view :
def view_discussion(request, discussion_id):
discussion = get_object_or_404(Discussion, id=discussion_id)
form = BaseMessageForm(request)
return render(request,'ulule/discussions/view_discussion.html', {
'discussion':discussion,
'form':form,
})
My form :
class BaseMessageForm(forms.Form):
message_content = forms.CharField(widget=forms.HiddenInput())
My template :
<form action="" method="post">
{% csrf_token %}
{% for field in form.visible_fields %}
<div class="fieldWrapper">
{% if forloop.first %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
{% endif %}
{{ field.errors }}
{{ field.label_tag }}: {{ field }}
</div>
{% endfor %}
<p><input type="submit" value="Send message" /></p>
</form>
Thanks a lot for your help !
I find that it's pretty common most people hardcode the navigation into their templates, but I'm dealing with a pretty dynamic news site which might be better off if the primary nav was db driven.
So I was thinking of having a Navigation model where each row would be a link.
link_id INT primary key
link_name varchar(255)
url varchar(255)
order INT
active boolean
If anyone's done something similar in the past, would you say this sort of schema is good enough?
I also wanted for there to be an optional dropdown in the admin near the url field so that a user could choose a Category model's slug since category links would be common, but I'm not quite sure how that would be possible.
If a have a form, with the data from a user, let's say a CV, and i save the data from the form into a database, but i don't want that a CV from the same user to be stored in the database more than once(when edited form instance)
I want it to be overwritten every time it is saved by one same user.
How can i do it?
thanks a lot
Hi,
how do you prepare i18n in your websites? I mean what do you do avoid the situation when you search for i18ned websites in Polish you get English description cause English is the default one.
Thanks in advance,
Etam.
Hi!
I want to include an initialized data structure in my request object, making it accessible in the context object from my templates. What I'm doing right now is passing it manually and tiresome within all my views:
render_to_response(...., ( {'menu': RequestContext(request)}))
The request object contains the key,value pair which is injected using a custom context processor. While this works, I had hoped there was a more generic way of passing selected parts of the request object to the template context. I've tried passing it by generic views, but as it turns out the request object isn't instantiated when parsing the urlpatterns list.
Hi,
I want to check if a user has any new messages each time they load the page. Up until now, I have been doing this inside of my views but it's getting fairly hard to maintain since I have a fair number of views now.
I assume this is the kind of thing middleware is good for, a check that will happen every single page load. What I need it to do is so:
Check if the user is logged in
If they are, check if they have any messages
Store the result so I can reference the information in my templates
Has anyone ever had to write any middleware like this? I've never used middleware before so any help would be greatly appreciated.
I want to let users use their google account to login to my website. Exactly the way SO lets me. Can anyone please point in the right direction? I'm assuming the oAuth library is to be used but what I'd really like is a snippet of code I can directly copy paste and get this to work.
I would like to use the EmailField in a form. However, instead of only storing
[email protected]
I want to store
"ACME Support" <[email protected]>
The reason is, that when I send email, I would like a "friendly name" to appear.
Can this be done?
if a have a declaration like
theclass = Classroom.objects.get(classname = classname)
members = theclass.members.all()
and i want to display all the members(of a class) in a template, how should i do it??
if i write:
{{theclass.members.all}}
the output is an empty list(though the class has some members)
How should the elements of a m2m table be displayed in a template?
thanks!
I've used django ImageFieldFile,
from django.db.models.fields.files import ImageFieldFile
now I want to restrict the user to use only Image files when uploading from browser
I followed the Djangoappengine instructions.
I used their django-testapp and copied the following folders in the django-testapp folder according to what I understood the instructions to say:
django
djangoappengine
djangotoolbox
I then started the dev server by running:
manage.py runserver
Then navigated to
http://localhost:8000/
and got the "It worked!" page, which is great, but it says the following at the bottom:
You're seeing this message because you
have DEBUG = True in your Django
settings file and you haven't
configured any URLs. Get to work!
I am an absolute beginner with Django and App Engine and Djangoappengine and Django-nonrel, so I am pretty lost.
How do I configure URLs? Or a link to the how to will help.
I took a look at the Django tutorial, but am unsure how much of it is relevant to Djangoappengine and Django-nonrel as a lot of the starting steps have to do with SQL databases.
Basically some direction on how to get my app running will be great.
Thanx much.
I'm trying to make a form that handles the checking of a domain: the form should fail based on a variable that was set earlier in another form.
Basically, when a user wants to create a new domain, this form should fail if the entered domain exists.
When a user wants to move a domain, this form should fail if the entered domain doesn't exist.
I've tried making it dynamic overload the initbut couldn't see a way to get my passed variabele to the clean function.
I've read that this dynamic validation can be accomplished using a factory method, but maybe someone can help me on my way with this?
Here's a simplified version of the form so far:
#OrderFormStep1 presents the user with a choice: create or move domain
class OrderFormStep2(forms.Form):
domain = forms.CharField()
extension = forms.CharField()
def clean(self):
cleaned_data = self.cleaned_data
domain = cleaned_data.get("domain")
extension = cleaned_data.get("extension")
if domain and extension:
code = whoislookup(domain+extension);
#Raise error based on result from OrderFormStep1
#raise forms.ValidationError('error, domain already exists')
#raise forms.ValidationError('error, domain does not exist')
return cleaned_data
I've been tasked with providing a workshop for my co-workers to teach them Django.
They're all good programmers but they've never done any web programming.
I was thinking to just go through the Django tutorial with them, but are there things in there that wouldn't make sense to non-web programmers?
Do they need any kind of webdev background first? Any thoughts on a good way to provide the basics so that Django will make sense?
I've got a view that I'm trying to test with the Client object. Can I get to the variables I injected into the render_to_response of my view?
Example View:
def myView(request):
if request.method == "POST":
# do the search
return render_to_response('search.html',{'results':results},context_instance=RequestContext(request))
else:
return render_to_response('search.html',context_instance=RequestContext(request)
Test:
c = Client()
response = c.post('/school/search/', {'keyword':'beagles'})
# how do I get to the 'results' variable??
if i have queries on multiple tables like:
d = Relations.objects.filter(follow = request.user).filter(date_follow__lt = last_checked)
r = Reply.objects.filter(reply_to = request.user).filter(date_reply__lt = last_checked)
article = New.objects.filter(created_by = request.user)
vote = Vote.objects.filter(voted = article).filter(date__lt = last_checked)
and i want to display the results from all of them ordered by date (i mean not listing all the replies, then all the votes, etc ).
Somehow, i want to 'join all these results', in a single queryset.
Is there possible?
this is the code:
http://code.google.com/p/google-app-engine-samples/source/browse/trunk/django_example
and can you import 'settings' to the views.py
thanks