Search Results

Search found 3554 results on 143 pages for 'django modelformsets'.

Page 87/143 | < Previous Page | 83 84 85 86 87 88 89 90 91 92 93 94  | Next Page >

  • Python: How can I override one module in a package with a modified version that lives outside the pa

    - by zlovelady
    I would like to update one module in a python package with my own version of the module, with the following conditions: I want my updated module to live outside of the original package (either because I don't have access to the package source, or because I want to keep my local modifications in a separate repo, etc). I want import statements that refer to original package/module to resolve to my local module Here's an example of what I'd like to do using specifics from django, because that's where this problem has arisen for me: Say this is my project structure django/ ... the original, unadulterated django package ... local_django/ conf/ settings.py myproject/ __init__.py myapp/ myfile.py And then in myfile.py # These imports should fetch modules from the original django package from django import models from django.core.urlresolvers import reverse # I would like this following import statement to grab a custom version of settings # that I define in local_django/conf/settings.py from django.conf import settings def foo(): return settings.some_setting Can I do some magic with the __import__ statement in myproject/__init__.py to accomplish this? Is there a more "pythonic" way to achieve this?

    Read the article

  • Does Python Django support custom SQL and denormalized databases with no Foreign Key relationships?

    - by Jay
    I've just started learning Python Django and have a lot of experience building high traffic websites using PHP and MySQL. What worries me so far is Python's overly optimistic approach that you will never need to write custom SQL and that it automatically creates all these Foreign Key relationships in your database. The one thing I've learned in the last few years of building Chess.com is that its impossible to NOT write custom SQL when you're dealing with something like MySQL that frequently needs to be told what indexes it should use (or avoid), and that Foreign Keys are a death sentence. Percona's strongest recommendation was for us to remove all FKs for optimal performance. Is there a way in Django to do this in the models file? create relationships without creating actual DB FKs? Or is there a way to start at the database level, design/create my database, and then have Django reverse engineer the models file?

    Read the article

  • How to use external static files with Django (serving external files once again)?

    - by Tomas Novotny
    Hi, even after Googling and reading all relevant posts at StackOverflow, I still can't get static files working in my Django application. Here is how my files look: settings.py MEDIA_ROOT = os.path.join(SITE_ROOT, 'static') MEDIA_URL = '/static/' urs.py from DjangoBandCreatorSite.settings import DEBUG if DEBUG: urlpatterns += patterns('', ( r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'static'} )) template: <script type="text/javascript" src="/static/jquery.js"></script> <script type="text/javascript"> I am trying to use jquery.js stored in directory "static". I am using: Windows XP Python 2.6.4 Django 1.2.3 Thank you very much for any help

    Read the article

  • Django 0.0.0.0:80; can't access remotely

    - by user349555
    Hello, I'm trying to access my Django server from another computer on the same network. I've set up my server and can view everything correctly usingpython manage.py runserver and going to http://127.0.0.1:8000 but when I try to use python manage.py runserver 0.0.0.0:80, I can't view my Django page from another computer. The computer hosting the Django server has intranet IP 192.168.1.146. On my secondary computer, I fire up a browser and try to access http://192.168.1.146:80 to no avail. I've also forwarded port 80 (and I've tried 8000 as well) also to no avail :(. HELP!

    Read the article

  • Django install on a shared host, .htaccess help

    - by redconservatory
    I am trying to install Django on a shared host using the following instructions: docs.google.com/View?docid=dhhpr5xs_463522g My problem is with the following line on my root .htaccess: RewriteRule ^(.*)$ /cgi-bin/wcgi.py/$1 [QSA,L] When I include this line I get a 500 error with almost all of my domains on this account. My cgi-bin directory is home/my-username/public_html/cgi-bin/ The wcgi.py file contains: #!/usr/local/bin/python import os, sys sys.path.insert(0, "/home/username/django/") sys.path.insert(0, "/home/username/django/projects") sys.path.insert(0, "/home/username/django/projects/newprojects") import django.core.handlers.wsgi os.chdir("/home/username/django/projects/newproject") # optional os.environ['DJANGO_SETTINGS_MODULE'] = "newproject.settings" def runcgi(): environ = dict(os.environ.items()) environ['wsgi.input'] = sys.stdin environ['wsgi.errors'] = sys.stderr environ['wsgi.version'] = (1,0) environ['wsgi.multithread'] = False environ['wsgi.multiprocess'] = True environ['wsgi.run_once'] = True application = django.core.handlers.wsgi.WSGIHandler() if environ.get('HTTPS','off') in ('on','1'): environ['wsgi.url_scheme'] = 'https' else: environ['wsgi.url_scheme'] = 'http' headers_set = [] headers_sent = [] def write(data): if not headers_set: raise AssertionError("write() before start_response()") elif not headers_sent: # Before the first output, send the stored headers status, response_headers = headers_sent[:] = headers_set sys.stdout.write('Status: %s\r\n' % status) for header in response_headers: sys.stdout.write('%s: %s\r\n' % header) sys.stdout.write('\r\n') sys.stdout.write(data) sys.stdout.flush() def start_response(status,response_headers,exc_info=None): if exc_info: try: if headers_sent: # Re-raise original exception if headers sent raise exc_info[0], exc_info[1], exc_info[2] finally: exc_info = None # avoid dangling circular ref elif headers_set: raise AssertionError("Headers already set!") headers_set[:] = [status,response_headers] return write result = application(environ, start_response) try: for data in result: if data: # don't send headers until body appears write(data) if not headers_sent: write('') # send headers now if body was empty finally: if hasattr(result,'close'): result.close() runcgi() Only I changed the "username" to my username...

    Read the article

  • ModelMultipleChoiceField and reverse()

    - by celopes
    I have a form containing a ModelMultipleChoiceField. Is it possible to come up with a url mapping that will capture a varying number of parameters from said ModelMultipleChoiceField? I find myself doing a reverse() call in the view passing the arguments of the form submission and realized that I don't know how to represent, in the urlconf, the multiple values from the SELECT tag rendered for the ModelMultipleChoiceField...

    Read the article

  • Error URL redirection

    - by xRobot
    urls.py: url(r'^book/(?P<booktitle>[\w\._-]+)/(?P<bookeditor>[\w\._-]+)/(?P<bookpages>[\w\._-]+)/(?P<bookid>[\d\._-]+)/$', 'book.views.book', name="book"), views.py: def book(request, booktitle, bookeditor, bookpages, bookid, template_name="book.html"): book = get_object_or_404(book, pk=bookid) if booktitle != book.book_title : redirect_to = "/book/%s/%s/%s/%s/%i/" % ( booktitle, bookeditor, bookpages, bookid, ) return HttpResponseRedirect(redirect_to) return render_to_response(template_name, { 'book': book, },) . So the urls of each book are like this: example.com/book/the-bible/gesu-crist/938/12/ I want that if there is an error in the url, then I get redirected to the real url by using book.id in the end of the url. For example if I go to: example.com/book/A-bible/gesu-crist/938/12/ the I will get redirected to: example.com/book/the-bible/gesu-crist/938/12/ but I go to wrong url I will get this error: TypeError at /book/A-bible/gesu-crist/938/12/ %d format: a number is required, not unicode . Why ? What I have to do ?

    Read the article

  • What causes the Openid error: Received "invalidate_handle" from server

    - by BryanWheelock
    I'm new to openid, and I am getting an "invalidate_handle" and I have no idea what to do to fix it. I'm using django_authopenid [Thu Apr 29 14:13:28 2010] [error] Generated checkid_setup request to https://www.google.com/accounts/o8/ud with assocication AOxxxxxxxxOX5-V9oDc3-btHhFxzAcccccccccc2RTHgh [Thu Apr 29 14:13:29 2010] [error] Error attempting to use stored discovery information: <openid.consumer.consumer.TypeURIMismatch: Required type http://specs.openid.net/auth/2.0/signon not found in ['http://specs.openid.net/auth/2.0/server', 'http://openid.net/srv/ax/1.0', 'http://specs.openid.net/extensions/ui/1.0/mode/popup', 'http://specs.openid.net/extensions/ui/1.0/icon', 'http://specs.openid.net/extensions/pape/1.0'] for endpoint <openid.consumer.discover.OpenIDServiceEndpoint server_url='https://www.google.com/accounts/o8/ud' claimed_id=None local_id=None canonicalID=None used_yadis=True >> [Thu Apr 29 14:13:29 2010] [error] Attempting discovery to verify endpoint [Thu Apr 29 14:13:29 2010] [error] Performing discovery on https://www.google.com/accounts/o8/id?id=AOxxxxxxxxOX5-V9oDc3-btHhFxzAcccccccccc2RTHgh [Thu Apr 29 14:13:29 2010] [error] Received id_res response from https://www.google.com/accounts/o8/ud using association AOxxxxxxxxOX5-V9oDc3-btHhFxzAcccccccccc2RTHgh [Thu Apr 29 14:13:29 2010] [error] Using OpenID check_authentication [Thu Apr 29 14:13:29 2010] [error] op_endpoint [Thu Apr 29 14:13:29 2010] [error] claimed_id [Thu Apr 29 14:13:29 2010] [error] identity [Thu Apr 29 14:13:29 2010] [error] return_to [Thu Apr 29 14:13:29 2010] [error] response_nonce [Thu Apr 29 14:13:29 2010] [error] assoc_handle [Thu Apr 29 14:13:29 2010] [error] Received "invalidate_handle" from server https://www.google.com/accounts/o8/ud

    Read the article

  • Using widthratio tag properly

    - by owca
    Hi. In my application I need to show in template stocks for my products. So from product view I'm returning variable {{stock}} which is my amount and then I'm trying to use it in template : <div class="bar_in" width="{% widthratio {{stock}} 10 100 %}px" style="background:black;"></div> But it constantly give me "Could not parse the remainder: '{{stock}}' from '{{stock}}' " error. I've tried casting it as int but still the same problem. How to make it work properly ?

    Read the article

  • How to save many to many fields by using an auto complete text box

    - by iHeartDucks
    If I have two models like class Author(models.Model): name = models.CharField(max_length=100) title = models.CharField(max_length=3, choices=TITLE_CHOICES) birth_date = models.DateField(blank=True, null=True) def __unicode__(self): return self.name class Book(models.Model): name = models.CharField(max_length=100) authors = models.ManyToManyField(Author) I can render the book form using a model form like this class BookForm(ModelForm): class Meta: model = Book widgets = { 'authors' : TextInput() } The authors fields is now rendered as a text box and I want to use an auto complete (where I can enter multiple authors) text box to populate the field. I am having a hard time to understand how I can save the authors in view function? I am thinking of using a hidden field to record all the author id's but I am having a hard time figuring out how to save it on the postback.

    Read the article

  • How to determine the maximum integer the model can handle?

    - by John Mee
    "What is the biggest integer the model field that this application instance can handle?" We have sys.maxint, but I'm looking for the database+model instance. We have the IntegerField, the SmallIntegerField, the PositiveSmallIntegerField, and a couple of others beside. They could all vary between each other and each database type. I found the "IntegerRangeField" custom field example here on stackoverflow. Might have to use that, and guess the lowest common denominator? Or rethink the design I suppose. Is there an easy way to work out the biggest integer an IntegerField, or its variants, can cope with?

    Read the article

  • post_save signal on m2m field

    - by Dmitry Shevchenko
    I have a pretty generic Article model, with m2m relation to Tag model. I want to keep count of each tag usage, i think the best way would be to denormalise count field on Tag model and update it each time Article being saved. How can i accomplish this, or maybe there's a better way?

    Read the article

  • Multiple filters on a data

    - by sridhary
    I want have have multiple filters on the data. like first i want to filter by date field and then by type field and then by some other field .... as many times as possible. i must pass on the field and value in the url and it must apply the filter and pass the data to the next filter.

    Read the article

  • MultipleHiddenInput doesn't encode properly over POST?

    - by andrew
    The form looks very simple: class MyForm(forms.Form): ids = forms.MultipleChoiceField(widget=forms.MultipleHiddenInput()) def view(request): ... form = MyForm(initial={'ids': [o.id for o in queryset]}) Which gives me the HTML (which looks good enough): <form method="post" action="/foo/bar/"> <input type="hidden" name="ids" value="7720889" id="id_ids_0"> <input type="hidden" name="ids" value="7717962" id="id_ids_1"> <input type="hidden" name="ids" value="7717807" id="id_ids_2"> <input type="hidden" name="ids" value="7713584" id="id_ids_3"> <input type="hidden" name="ids" value="7712277" id="id_ids_4"> <input type="hidden" name="ids" value="7707475" id="id_ids_5"> <input type="hidden" name="ids" value="7707257" id="id_ids_6"> <input type="hidden" name="ids" value="7705271" id="id_ids_7"> <input type="hidden" name="ids" value="7704338" id="id_ids_8"> <input type="hidden" name="ids" value="7704137" id="id_ids_9"> <input type="hidden" name="ids" value="7695444" id="id_ids_10"> <input type="hidden" name="ids" value="7695242" id="id_ids_11"> <input type="hidden" name="ids" value="7690683" id="id_ids_12"> <input type="hidden" name="ids" value="7690431" id="id_ids_13"> <input type="hidden" name="ids" value="7689035" id="id_ids_14"> <input type="hidden" name="ids" value="7681230" id="id_ids_15"> <input type="hidden" name="ids" value="7679189" id="id_ids_16"> <input type="hidden" name="ids" value="7675315" id="id_ids_17"> <input type="hidden" name="ids" value="7667291" id="id_ids_18"> <input type="hidden" name="ids" value="7661162" id="id_ids_19"> <button type="submit">Test</button> </form> But, in the POST that comes in, I'm only getting one value: <QueryDict: {u'ids': [u'7661162']}> What gives? What am I doing wrong?

    Read the article

  • wierd FileField url in admin site

    - by panchicore
    My model class TheFile(models.Model): document = models.FileField(upload_to="archivos") The wierd HTML admin link: <a hacking_google_maps_and_google_earth.pdf="" archivos="" media="" localhost:8000="" http:="" href="" target="_blank">archivos/Hacking_Google_Maps_And_Google_Earth.pdf</a> If I firebug-edit the href="" it works :S

    Read the article

  • weird FileField url in admin site

    - by panchicore
    My model class TheFile(models.Model): document = models.FileField(upload_to="archivos") The weird HTML admin link: <a hacking_google_maps_and_google_earth.pdf="" archivos="" media="" localhost:8000="" http:="" href="" target="_blank">archivos/Hacking_Google_Maps_And_Google_Earth.pdf</a> If I firebug-edit the href="" it works :S

    Read the article

  • cleaned_data() doesn't have some of the entered data

    - by SC Ghost
    I have a simple form for a user to enter in Name (CharField), Age(IntegerField), and Sex(ChoiceField). However the data that is taken from the Sex choice field is not showing up in my cleaned_data(). Using a debugger, I can clearly see that the data is being received in the correct format but as soon as I do form.cleaned_data() all sign of my choice field data is gone. Any help would be greatly appreciated. Here is the relative code: class InformationForm(forms.Form): Name = forms.CharField() Age = forms.IntegerField() Sex = forms.ChoiceField(SEX_CHOICES, required=True) def get_information(request, username): if request.method == 'GET': form = InformationForm() else: form = RelativeForm(request.POST) if form.is_valid(): relative_data = form.cleaned_data

    Read the article

  • create_or_update in ModelForm

    - by ykaganovich
    I want to have a ModelForm that can create_or_update a model instance based on the request parameters. I've been trying to cobble something together, but am realizing that my python fu is not strong enough, and the ModelForm implementation code is a quite hairy. I found this create_or_update snipplet for working with a Model, but I think it would be incredibly useful if it were integrated with a ModelForm. I would expect it to behave similarly to ModelForm.save(): class BetterModelForm(forms.ModelForm): def init(self, *args, **kwargs) def create_or_update(self): #magic return (instance, created, updated) Conversely I'd also be interested in hearing compelling reasons why this is not a good idea.

    Read the article

  • Working with extra fields in an Inline form - save_model, save_formset, can't make sense of the diff

    - by magicrebirth
    Suppose I am in the usual situation where there're extra fields in the many2many relationship: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(Person, through='Membership') class Membership(models.Model): person = models.ForeignKey(Person) group = models.ForeignKey(Group) date_joined = models.DateField() invite_reason = models.CharField(max_length=64) # other models which are unrelated to the ones above.. class Trip(models.Model): placeVisited = models.ForeignKey(Place) visitor = models.ForeignKey(Person) pleasuretrip = models.Boolean() class Place(models.Model): name = models.CharField(max_length=128) I want to add some extra fields in the Membership form that gets displayed through the Inline. These fields basically are a shortcut to the instantiation of another model (Trip). Trip can have its own admin views, but these shortcuts are needed because when my project partners are entering 'Membership' data in the system they happen to have also the 'Trip' information handy (and also because some of the info in Membership can just be copied over to Trip etc. etc.). So all I want to have is two extra fields in the Membership Inline - placeVisited and pleasuretrip - which together with the Person instance will let me instantiate the Trip model in the background... I found out I can easily add extra fields to the inline view by defining my own form. But once the data have been entered, how and when to reference to them in order to perform the save operations I need to do? class MyForm(forms.ModelForm): place = forms.ModelChoiceField(required=False, queryset=Place.objects.all(), label="place",) pleasuretrip = forms.BooleanField(required=False, label="...") class MembershipInline(admin.TabularInline): model = Membership form = MyForm def save_model(self, request, obj, form, change): place = form.place pleasuretrip = form.pleasuretrip person = form.person .... # now I can create Trip instances with those data .... obj.save() class GroupAdmin(admin.ModelAdmin): model = Group .... inlines = (MembershipInline,) This doesn't seem to work... I'm also a bit puzzled by the save_formset method... maybe is that the one I should be using? Many thanks in advance for the help!!!!

    Read the article

  • Error while executing query

    - by iHeartDucks
    I get an error message on this query query = "select count(*) from pgns_game where raw_moves = %s" params = ('a',) total_rows = self.model.objects.raw(query, params) and it says InvalidQuery('Raw query must include the primary key') I am clearly missing something but I don't know what. Any ideas?

    Read the article

  • Explanation of contribute_to_class

    - by anon.
    I'm attempted to extend code, and have come across an issue, I don't understand a line of code. I know the outcome of it - but I don't understand how it happens and am naturally enough scared to change it. The line of code I've come across is this: MyGenericRelation().contribute_to_class(model, 'field_name') The result of this code is a field with 'field_name' is added to the 'model' and from what I gather the objects inside the field are a list of type X (part of MyGenericRelation). I'm wondering if anyone can explain how this works. As in, why do I get a list of X objects attached to 'field_name' and if does it have to be generic relations prior to contribute_to_class or would using an actual model type, say 'Y' just give me a list of Y's. To be honest, I am more interested in the affect and functionality of the contribute_to_class method.

    Read the article

  • ModelForm problem

    - by 47
    I have declared my model classes as found in this link....I now want to customize how my add/edit ModelForm for a Vehicle object is rendered in that I want the year, make, model, and manufacturer fields to be rendered separately as opposed to referring to the one common_vehicle field from the Vehicle class. How can this be done?

    Read the article

  • More strict query yields more results?

    - by Mark
    I've got a query that looks like this affiliates = User.objects.annotate(referral_count=Count('referrals')).filter(referral_count__gt=0) But when I restrict it more by adding referrals__user__date_joined__gt=start_date to the filter, I get even higher referral counts. I'm trying to count the number of people a user has referred within a time period. The relevant model looks like this: class Profile(models.Model): user = models.ForeignKey(User, unique=True, related_name='profile') referred_by = models.ForeignKey(User, null=True, blank=True, related_name='referrals') In contrast, when I try it like this: affiliates = User.objects \ .exclude(referrals__user__date_joined__lte=sd, referrals__user__date_joined__gt=ed) \ .annotate(referral_count=Count('referrals')) \ .filter(referral_count__gt=0) The exclude statement seems to do nothing... the counts don't change (should be 0 if no referred users have joined within that time period, but it isn't).

    Read the article

< Previous Page | 83 84 85 86 87 88 89 90 91 92 93 94  | Next Page >