I want to send an image from the android client to the Django server using Http Post. The image is chosen from the gallery. At present, I am using list value name Pairs to send the necessary data to the server and receiving responses from Django in JSON. Can the same approach be used for images (with urls for images embedded in JSON resp...
I'm trying to setup a User - UserProfile relationship, display the form and save the data.
When submitted, the data is saved, except the password field doesn't get hashed.
Forms.py
class UserForm(forms.ModelForm):
username = forms.RegexField(label="Username", max_length=30, regex=r'^[\w.@+-]+$', help_text = "My text", error_messages =...
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(re...
I'd like to browse active classes in Django. I think I'd learn a lot that way. So what's a good way to do that?
I could use IDLE if I knew how to start Django from within IDLE. But as I'm new to Python/Django, I'm not particularly wedded to IDLE. Other alternatives?
...
I have a variable called STATIC_URL, declared in settings.py in my base project:
STATIC_URL = '/site_media/static/'
This is used, for example, in my site_base.html, which links to CSS files as follows:
<link rel="stylesheet" href="{{ STATIC_URL }}css/site_tabs.css" />
I have a bunch of templates related to different apps which exte...
I'm using both django-registrations and django-profiles. When the user registers I'd like to ask them to fill in the form fields from profiles as well as the usual username and password. How do I combine these two into one sign up page?
...
While it is recommended to use the following construct to check whether request is POST,
if request.method == 'POST':
pass
It is likely that people will find
if request.POST:
pass
to be more elegant and concise.
Are there any reasons not to use it, apart from personal preference?
...
What I want to do is pretty simple:
f=Foobar.objects.get(id=1)
foo='somefield'
bar='somevalue'
f.foo=bar
f.save()
This doesn't work as it tries to update the f object's 'foo' field, which of course doesn't exist. How can I accomplish this?
...
I have a Django web site which I want ot be viewable in different languages. Until this morning everything was working fine. Here is the deal. I go to my say About Us page and it is in English. Below it there is the change language button and when I press it everything "magically" translates to Bulgarian just the way I want it. On the ot...
I am trying to sort/narrow a queryset of objects based on the number of comments each object has as well as by the timeframe during which the comments were posted. Am using a queryset.extra() method (using django_comments which utilizes generic foreign keys).
I got the idea for using queryset.extra() (and the code) from here. This i...
Django's internationalization is very nice (gettext based, LocaleMiddleware), but what is the proper way to translate the model name and the attributes for admin pages? I did not find anything about this in the documentation:
http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/
http://www.djangobook.com/en/2.0/chapter...
Hello guys!
So, here is what I want to do.
I have a model Staff, that has a foreign key to the User model. I also have a model Match that has a foreign key to the User model.
I want to select how much Matches every Staff has. I don't know how to do that, so far I only got it working for the User model. From Staff, it will not allow to a...
My Book model has an author attribute which today is simply a CharField. The value for author should be one of the registered users of my Django site. When creating a new Book object in Django admin, I would like author to be displayed as a combo box showing all registered users. How would I go about achieving this?
...
Hi folks,
I recently wrote a simple and tiny embedded HTTP server for my C++ app (QT) and I played a little bit with Ry's http-parser and loved it. This guy is crazy.
So I told to myself: "Hey! Why not port the django template engine to C?" That'd be awesome!
I know, it won't be an easy task (not at all, I know) but I'd really love to...
I'm trying to initialize the form attribute for MyModelAdmin class inside an instance method, as follows:
class MyModelAdmin(admin.ModelAdmin):
def queryset(self, request):
MyModelAdmin.form = MyModelForm(request.user)
My goal is to customize the editing form of MyModelForm based on the current session. When I try this ho...
Django newbie here.
I wrote simplified login form which takes email and password. It works great if both email and password are supplied, but if either is missing i get KeyError exception. According to django documentation this should never happen:
By default, each Field class assumes the value is required, so if you pass an empty v...
Does select_related work for GenericRelation relations, or is there a reasonable alternative? At the moment Django's doing individual sql calls for each item in my queryset, and I'd like to avoid that using something like select_related.
class Claim(models.Model):
proof = generic.GenericRelation(Proof)
class Proof(models.Model):
...
class Votes(models.Model):
field1 = models.ForeignKey(Blah1)
field2 = models.ForeignKey(Blah2)
class Meta:
unique_together = (("field1","field2"),)
I am using this code as one of my models. Now i wanted to know two things:
1. It doesn't show any error and it saved an entry which wasn't unique together; S...
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")
likes = models.ForeignKey(User, related_name="likes")
........
#at some view
user = request.user
foos...
I have a MySQL database called People which contains the following schema <id,name,foodchoice1,foodchoice2>. The database contains a list of people and the two choices of food they wish to have at a party (for example). I want to create some kind of Python web-service that will output a JSON object.
An example of output should be like:...