django-1.4

Cross-referencing foreign keys in Django 1.4

◇◆丶佛笑我妖孽 提交于 2019-12-23 03:37:08
问题 I have a Django project where I would need two models to have a foreign key to each other. However this is not possible because two Python files would have to import each other which Python doesn't allow. What is the best way to solve this problem? So my code currently looks like this: countries/models.py: from django.db.models import Model, ForeignKey from users.models import Profile class Country(Model): president = ForeignKey(Profile) users/models.py: from django.db.models import Model,

custom save method on model - django

☆樱花仙子☆ 提交于 2019-12-20 10:43:20
问题 I am overriding the save method on one of my models: def save(self, *args, **kwargs): self.set_coords() super(Post, self).save(*args, **kwargs) def __unicode__(self): return self.address # set coordinates def set_coords(self): toFind = self.address + ', ' + self.city + ', ' + \ self.province + ', ' + self.postal (place, location) = g.geocode(toFind) self.lat = location[0] self.lng = location[1] However, I only want to run set_coords() once, when the post is being created. This function should

South + Django 1.4 Database error

孤者浪人 提交于 2019-12-20 10:24:09
问题 I have just installed my Django project on a new system, and installed Django 1.4. However when I try to run manage.py runserver or manage.py syncdb I get this error from South: Validating models... Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x1a67810>> Traceback (most recent call last): File "/home/saul/.virtualenvs/canada/lib/python2.7/site-packages/django/core/management/commands

Django 1.4 static file not found error [duplicate]

女生的网名这么多〃 提交于 2019-12-13 22:19:29
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Trying to serve django static files on development server - not found I just entered the world of Python and django, i am unable to set my URL using the STATIC_URL , i am currently developing locally with django 1.4. I read the django static file doc and seem to have added all what's required, but still get a 404 error. I have read other Q&A on SO related to this, and tried all sorts of things, but could not

Django 1.4 static files problems and don't render at other urls of my project

拜拜、爱过 提交于 2019-12-12 14:33:36
问题 Here are my settings: STATIC_ROOT = "/home/tony/Documents/mysite/mysite/" STATIC_URL = '/static/' STATICFILES_DIRS = ( "/home/tony/Documents/mysite/mysite/static/", ) And here I refer my stylesheet(This gives me an error): <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}/css/reset.css" /> <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}/css/style.css" /> And the error in the log: [06/Apr/2012 13:36:09] "GET /css/reset.css HTTP/1.1" 404 2193 [06/Apr/2012 13:36:09]

Filter on prefetch_related in Django

六月ゝ 毕业季﹏ 提交于 2019-12-12 08:18:59
问题 Is there a way of filtering prefetched objects? I need to get the latest() of the prefetched objects but prefetch_related doesn't work if you use latest because the query is changed? The example here does what I need but I was hoping there's a simpler workaround... https://github.com/ionelmc/django-prefetch#example 回答1: As of Django 1.7, filtering prefetched objects is possible. See this SO answer, and the Django documentation. 回答2: It is very simple method which is hardly comparable with

django.template.base.TemplateSyntaxError: 'block' tag with name 'bottom_js' appears more than once

两盒软妹~` 提交于 2019-12-12 01:09:16
问题 I have this error : django.template.base.TemplateSyntaxError: 'block' tag with name 'bottom_js' appears more than once But I have no clue which template is at fault, how do I find this out ? Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/maazza/.virtualenvs/list_app/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line utility.execute() File "/home/maazza/

Django url template tag {% url %} error on django 1.4

冷暖自知 提交于 2019-12-11 23:15:23
问题 I made this many times and it worked, but not this time. I get this error when I try to use {% url path.to.view %} django's template tage: AttributeError at /login/ 'str' object has no attribute 'regex' urls.py (main) urlpatterns= patterns('', (r'', include('authenticate.urls')), ) urls.py (my app) urlpatterns= patterns('authenticate.views', url(r'^login/$','login'),) login.html {{ form }} {% url authenticate.views.login %} < --- Error comes here in the views: return render_to_response('login

Passing Parameters to An Overrode View in Django/Allauth

放肆的年华 提交于 2019-12-11 03:54:05
问题 With Django 1.4 and Allauth, I'm trying to have 2 different signup pages. When I say different, I mean 2 different URLs and 'html layouts'. Here's what I did so far. It 'works', but it doesn't pass the 'is_alternate_template' variable to the HTML template: In urls.py: url(r'^accounts/', include('allauth.urls')), url(r'^abc/alternate-signup/?$','project.views.alternate_signup'), in views.py: def alternate_signup(request): from allauth.account import views as account_views is_alternate_template

Function-based generic views have been deprecated

前提是你 提交于 2019-12-11 03:07:37
问题 DeprecationWarning: Function-based generic views have been deprecated; use class-based views instead. I keep getting this warning, when I'm running my site. What does this mean and how can I fix it? 回答1: Django 1.3 introduced class-based views and also added a range of generic class-based views. Django also has documentation about migrating function-based views to class-based views. There is not really much more to say about it: your project currently uses function-based views whereas class