Search Results

Search found 15813 results on 633 pages for 'django settings'.

Page 75/633 | < Previous Page | 71 72 73 74 75 76 77 78 79 80 81 82  | Next Page >

  • Autodiscovery for inclusion tags

    - by Ludwik Trammer
    The title may be a little confusing, but I don't know how else to call it. I would like to create a Django project with a large set of applications you could arbitrary turn on or off using INSTALLED_APPS option in settings.py (you would obviously also need to edit urls.py and run syncdb). After being turned on an app should be able to automatically: Register it's content in site-wide search. Luckily django-haystack has this built-in, so it's not a problem. Register cron jobs. django-cron does exactly that. Not a problem. Register a widget that should be displayed on the homepage. The homepage should include a list of boxes with widgets form different applications. I thought about inclusion tags, because you can put them anywhere on a page and they control both content and presentation. The problem is I don't know how to automatically get a list of inclusion tags provided by my applications, and display them one by one on a homepage. I need a way to register them somehow, and then display all registered tags.

    Read the article

  • Render multiple Form instances

    - by vorpyg
    I have a simple application where users are supposed to bet on outcome of a match. A match consists of two teams, a result and a stake. Matches with teams are created in the Django admin, and participants are to fill in result and stake. The form must be generated dynamically, based on the matches in the database. My idea is to have one (Django) Form instance for each match and pass these instances to the template. It works fine when I do it from django shell, but the instances aren't rendered when I load my view. The form looks like this: class SuggestionForm(forms.Form): def __init__(self, *args, **kwargs): try: match = kwargs.pop('match') except KeyError: pass super(SuggestionForm, self).__init__(*args, **kwargs) label = match self.fields['result'] = forms.ChoiceField(label=label, required=True, choices=CHOICES, widget=forms.RadioSelect()) self.fields['stake'] = forms.IntegerField(label='', required=True, max_value=50, min_value=10, initial=10) My (preliminary) view looks like this: def suggestion_form(request): matches = Match.objects.all() form_collection = {} for match in matches: f = SuggestionForm(request.POST or None, match=match) form_collection['match_%s' % match.id] = f return render_to_response('app/suggestion_form.html', { 'forms': form_collection, }, context_instance = RequestContext(request) ) My initial thought was that I could pass the form_collection to the template and the loop throught the collection like this, but id does not work: {% for form in forms %} {% for field in form %} {{ field }} {% endfor %} {% endfor %} (The output is actually the dict keys with added spaces in between each letter - I've no idea why…) It works if I only pass one Form instance to the template and only runs the inner loop. Suggestions are greatly appreciated.

    Read the article

  • Testing InlineFormset clean methods

    - by Rory
    I have a Django project, with 2 models, a Structure and Bracket, the Bracket has a ForeignKey to a Structure (i.e. one-to-many, one Structure has many Brackets). I created a TabularInline for the admin site, so that there would be a table of Brackets on the Structure. I added a custom formset with some a custom clean method to do some extra validation, you can't have a Bracket that conflicts with another Bracket on the same Structure etc. The admin looks like this: class BracketInline(admin.TabularInline): model = Bracket formset = BracketInlineFormset class StructureAdmin(admin.ModelAdmin): inlines = [ BracketInline ] admin.site.register(Structure, StructureAdmin) That all works, and the validation works. However now I want to write some unittest to test my complex formset validation logic. My first attempt to validate known-good values is: data = {'form-TOTAL_FORMS': '1', 'form-INITIAL_FORMS': '0', 'form-MAX_NUM_FORMS': '', 'form-0-field1':'good-value', … } formset = BracketInlineFormset(data) self.assertTrue(formset.is_valid()) However that doesn't work and raises the exception: ====================================================================== ERROR: testValid (appname.tests.StructureTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/paht/to/project/tests.py", line 494, in testValid formset = BracketInlineFormset(data) File "/path/to/django/forms/models.py", line 672, in __init__ self.instance = self.fk.rel.to() AttributeError: 'BracketInlineFormset' object has no attribute 'fk' ---------------------------------------------------------------------- The Django documentation (for formset validation) implies one can do this. How come this isn't working? How do I test the custom clean()/validation for my inline formset?

    Read the article

  • Automatically use inclusion tags (?) in a template, depending on installed apps

    - by Ludwik Trammer
    The title may be a little confusing, but I don't know how else to call it. I would like to create a Django project with a large set of applications you could arbitrary turn on or off using INSTALLED_APPS option in settings.py (you would obviously also need to edit urls.py and run syncdb). After being turned on an app should be able to automatically: Register it's content in site-wide search. Luckily django-haystack has this built-in, so it's not a problem. Register cron jobs. django-cron does exactly that. Not a problem. Register a widget that should be displayed on the homepage. The homepage should include a list of boxes with widgets form different applications. I thought about inclusion tags, because you can put them anywhere on a page and they control both content and presentation. The problem is I don't know how to automatically get a list of inclusion tags provided by my applications, and display them one by one on a homepage. I need a way to register them somehow, and then display all registered tags.

    Read the article

  • Get Username from a Cookie

    - by craphunter
    Hi, I use the backend solution from django. I just want to get a username from the cookie or the session_key to get to know the user. How I can do it? from django.contrib.auth.models import User from django.contrib.sessions.models import Session def start(request, template_name="registration/my_account.html"): user_id = request.session.get('session_key') if user_id: name = request.user.username return render_to_response(template_name, locals()) else: return render_to_response('account/noauth.html') Only else is coming up. What am I doing wrong? Am I right then that authenticated means he is logged in? -- Okay this I got! Firstly, if you have some clarification to a question, update the question, don't post an answer or (even worse) another question, as you have done. Secondly, if the user is logged out, by definition he doesn't have a username. I mean the advantage of Cookies is to identify a user again. I just want to place his name on the webpage. Even if he is logged out. Or isnt't it possible?

    Read the article

  • Django/PIL Error - Caught an exception while rendering: The _imagingft C module is not installed

    - by kenok
    I'm trying to run a webapp/site on my machine, it's running on OSX 10.6.2 and I'm having some problems: Caught an exeption while rending: The _imagingft C module is not installed Doing import _imagingft in python gives me this: >>> import _imagingft Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: dlopen(/Library/Python/2.6/site-packages/PIL/_imagingft.so, 2): Symbol not found: _FT_Done_Face Referenced from: /Library/Python/2.6/site-packages/PIL/_imagingft.so Expected in: flat namespace in /Library/Python/2.6/site-packages/PIL/_imagingft.so It's seems that the Freetype library is the one having problems. No errors so far when installing PIL or when I compiled(?) the jpeg and freetype libraries so far. I'm on django 1.1.1, python 2.6.2.

    Read the article

  • Django CMS malfunction: Site matching query does not exist

    - by culebrón
    I've installed all apps in a project, then added a site in the sites section, and deleted example.com. Now Pages section in Django CMS 2.0 isn't working: it raises a DoesNotExist exception: Site matching query does not exist. at http://127.0.0.1:8000/admin/cms/page/ The section worked normally before I deleted the example.com site. In settings.py I have SITE_ID = 2 line. Still, in this call: return Site.objects.get(pk=site_pk) in traceback, site_pk=1. How can I fix this?

    Read the article

  • Django Forms, Foreign Key and Initial retuen all associated values

    - by gramware
    I a working with Django forms. The issue I have is that Foreign Key fields and those using initial take all associated entries (all records associated with that record other then the one entry i wanted e.g instead of getting a primary key, i get the primary key, post subject, post body and all other values attributed with that record). The form and the other associated queries still work well, but this behaviour is clogging my database. How do i get the specific field i want instead of all records. An example of my models is here: A form field for childParentId returns postID, postSubject and postBody instead of postID alone. Also form = ForumCommentForm(initial = {'postSubject':forum.objects.get(postID = postID), }) returns all records related to postID. class forum(models.Model): postID = models.AutoField(primary_key=True) postSubject = models.CharField(max_length=25) postBody = models.TextField() postPoster = models.ForeignKey(UserProfile) postDate = models.DateTimeField(auto_now_add=True) child = models.BooleanField() childParentId = models.ForeignKey('self',blank=True, null=True) deleted = models.BooleanField() def __unicode__(self): return u'%s %s %s %s %s' % (self.postSubject, self.postBody, self.postPoster, self.postDate, self.postID

    Read the article

  • Django URL regex question

    - by shawnjan
    Hey all! I had a quick question about Django URL configuration, and I guess REGEX as well. I have a small configuration application that takes in environments and artifacts in the following way: url(r'^env/(?P<env>\w+)/artifact/(?P<artifact>\w+)/$', 'config.views.ipview', name="bothlist"), Now, this works fine, but what I would like to do is have it be able to have additional parameters that are optional, such as a verbose mode or no formating mode. I know how to do this just fine in the views, but I can't wrap my head around the regex. the call would be something like GET /env/<env>/artifact/<artifact>/<opt:verbose>/<opt:noformat> Any help would be appreciated, thanks! -Shawn

    Read the article

  • How do I create sub-applications in Django?

    - by jamida
    I'm a Django newbie, but fairly experienced at programming. I have a set of related applications that I'd like to group into a sub-application but can not figure out how to get manage.py to do this for me. Ideally I'll end up with a structure like: project/ app/ subapp1/ subapp2/ I've tried: manage.py startapp app.subapp1 manage.py startapp app/subapp1 but this tells me that / and . are invalid characters for app names I've tried changing into the app directory and running ../manage.py subapp1 but that makes supapp1 at the top level. NOTE, I'm not trying to directly make a stand-alone application. I'm trying to do all this from within a project.

    Read the article

  • What should I use - Mako or Django?

    - by mridang
    Hi guys, I'm making a website that mail users when a movie or a pc game has released. It isn't too complex - users can sign up, choose movies/music or a genre and save the settings. When the movie/music is released - it mails the user. Some other functionality too but this is the jist. Now, I've been working with Python for a bit but mainly in the area of console apps. For web: what should I use, the web framework Django or the templating engine Mako? I can't seem to decide between the two. :( Thanks

    Read the article

  • Django Forms, Foreign Key and Initial return all associated values

    - by gramware
    I a working with Django forms. The issue I have is that Foreign Key fields and those using initial take all associated entries (all records associated with that record other then the one entry i wanted e.g instead of getting a primary key, i get the primary key, post subject, post body and all other values attributed with that record). The form and the other associated queries still work well, but this behaviour is clogging my database. How do i get the specific field i want instead of all records. An example of my models is here: A form field for childParentId returns postID, postSubject and postBody instead of postID alone. Also form = ForumCommentForm(initial = {'postSubject':forum.objects.get(postID = postID), }) returns all records related to postID. class forum(models.Model): postID = models.AutoField(primary_key=True) postSubject = models.CharField(max_length=25) postBody = models.TextField() postPoster = models.ForeignKey(UserProfile) postDate = models.DateTimeField(auto_now_add=True) child = models.BooleanField() childParentId = models.ForeignKey('self',blank=True, null=True) deleted = models.BooleanField() def __unicode__(self): return u'%s %s %s %s %s' % (self.postSubject, self.postBody, self.postPoster, self.postDate, self.postID

    Read the article

  • Objects with permissions assigned by django-guardian not visible in admin

    - by jul
    I'm using django-guardian in order to manage per object permission. For a given user I give permission all permission on one object: joe = User.objects.get(username="joe") mytask = Task.objects.get(pk=1) assign('add_task', joe, mytask) assign('change_task', joe, mytask) assign('delete_task', joe, mytask) and I get, as expected: In [57]: joe.has_perm("add_task", mytask) Out[57]: True In [58]: joe.has_perm("change_task", mytask) Out[58]: True In [59]: joe.has_perm("delete_task", mytask) Out[59]: True In admin.py I also make TaskAdmin inherit from GuardedModelAdmin instead of admin.ModelAdmin Now when I connect to my site with joe, on the admin I get: You don't have permission to edit anything Am I not supposed to be able to edit the object mytask? Do I have to set some permissions using the built-in model-based permission system? Am I missing anything? Thank you

    Read the article

  • Django query if field value is one of multiple choices

    - by Nathan
    Say I want to model a system where a piece of data can have multiple tags (e.g. a question on a StackOverflow is the data, it's set of tags are the tags). I can model this in Django with the following: class Tag(models.Model): name = models.CharField(10) class Data(models.Model): tags = models.ManyToManyField(Tag) Given a set of strings, what's the best way to go about finding all Data objects that have one of these strings as the name of a tag in their tag list. I've come up with the following, but can't help thinking there is a more "Djangonic" way. Any ideas? tags = [ "foo", "bar", "baz" ] q_objects = Q( tags__name = tags[0] ) for t in tags[1:]: q_objects = q_objects | Q( tags__name = t ) data = Data.objects.filter( q_objects ).distinct()

    Read the article

  • Passing context between templatetags, django

    - by Kasper Gadensgaard
    Hi overflowers, I am using django to create a web-application. I have created a template in where I load a templatetag. In this templatetag i load another templatetag. From the template I pass context to the first templatetag, but the context is not available from the second templatetag (inside the first templatetag) - see below. I hope this makes sense, and that one of you have the answer. Thanks in advance Regards Kasper Gadensgaard Template snippit: {% load templatetags %} {% some_tag argument %} some_tag Templatetag: {% load templatetags %} {% some_other_tag another_argument %} some_other_tag Templatetag: In this templatetag i am trying to access context to get user info i.e. using request = context['request'] request.user

    Read the article

  • Dynamically generate PDF and email it using django

    - by Shane
    I have a django app that dynamically generates a PDF (using reportlab + pypdf) from user input on an HTML form, and returns the HTTP response with an application/pdf MIMEType. I want to have the option between doing the above, or emailing the generated pdf, but I cannot figure out how to use the EmailMessage class's attach(filename=None, content=None, mimetype=None) method. The documentation doesn't give much of a description of what kind of object content is supposed to be. I've tried a file object and the above application/pdf HTTP response. I currently have a workaround where my view saves a pdf to disk, and then I attach the resulting file to an outgoing email using the attach_file() method. This seems wrong to me, and I'm pretty sure there is a better way.

    Read the article

  • Django and Reportlab Question

    - by Hellnar
    Hello, I have written this small Django view to return pdf. @login_required def code_view(request,myid): try: deal = Deal.objects.get(id=myid) except: raise Http404 header = deal.header code = deal.code response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=code.pdf' p = canvas.Canvas(response) p.drawString(10, 800, header) p.drawString(10, 700, code) p.showPage() p.save() return response And my questions: Utf-8 characters are not shown correctly within the pdf. How can I include an image ? How can I include a very basic html such as: . <ul> <li>List One</li> <li>List Two</li> <li>List Three</li> </ul>

    Read the article

  • Loading fixtures in django unit tests

    - by loder
    I'm trying to start writing unit tests for django and I'm having some questions about fixtures: I made a fixture of my whole project db (not certain application) and I want to load it for each test, because it looks like loading only the fixture for certain app won't be enough. I'd like to have the fixture stored in /proj_folder/fixtures/proj_fixture.json. I've set the FIXTURE_DIRS = ('/fixtures/',) in my settings.py. Then in my testcase I'm trying fixtures = ['proj_fixture.json'] but my fixtures don't load. How can this be solved? How to add the place for searching fixtures? In general, is it ok to load the fixture for the whole test_db for each test in each app (if it's quite small)? Thanks!

    Read the article

  • general database modeling and django specific modeling

    - by Shreko
    I'm wondering what is the best way to model something like the following. Lets say my company sells metal bars (parameters/fields are: length, profile_type, quantity etc.) of different profiles, where profiles may be pipe(pipe_diameter, wall_thickness) or hollow_rectangle(base, height, wall_thickness), or maybe some other profile with different parameters. Lets say maximum number of profiles would be 12, each profile having between 2-5 parameters. Should everything be in a single table like table_bars: id, length, quantity, profile_type, pipe_diameter, wall_thickness, base, height, etc.) where profile type would be (pipe, rectangle etc.) or should every shape have its own table with its own parameters and in table_bars keep only id, length, quantity profile_type and profile_id) and are there any django specific issues is multiple tables are the best answer? Thanks

    Read the article

  • Unicode issue in Django

    - by Kave
    I seem to have a unicode problem with the deal_instance_name in the Deal model. It says: coercing to Unicode: need string or buffer, __proxy__ found The exception happens on this line: return smart_unicode(self.deal_type.deal_name) + _(u' - Set No.') + str(self.set) The line works if I remove smart_unicode(self.deal_type.deal_name) but why? Back then in Django 1.1 someone had the same problem on Stackoverflow I have tried both the unicode() as well as the new smart_unicode() without any joy. What could I be missing please? class Deal(models.Model): def __init__(self, *args, **kwargs): super(Deal, self).__init__(*args, **kwargs) self.deal_instance_name = self.__unicode__() deal_type = models.ForeignKey(DealType) deal_instance_name = models.CharField(_(u'Deal Name'), max_length=100) set = models.IntegerField(_(u'Set Number')) def __unicode__(self): return smart_unicode(self.deal_type.deal_name) + _(u' - Set No.') + str(self.set) class Meta: verbose_name = _(u'Deal') verbose_name_plural = _(u'Deals') Dealtype: class DealType(models.Model): deal_name = models.CharField(_(u'Deal Name'), max_length=40) deal_description = models.TextField(_(u'Deal Description'), blank=True) def __unicode__(self): return smart_unicode(self.deal_name) class Meta: verbose_name = _(u'Deal Type') verbose_name_plural = _(u'Deal Types')

    Read the article

  • making apache and django add a trailing slash

    - by user302099
    Hello. My /train directory is aliased to a script in httpd.conf by: WSGIScriptAlias /train /some-path/../django.wsgi And it works well, except for one problem. If a user goes to /train (with no trailing slash) it will not redirect him to /train/, but will just give him the right page. This is a problem because this way the relative links on this page lead to the wrong place when no trailing slash was used to access it. How can this be worked out? Thanks.

    Read the article

  • Django vs. Pylons

    - by Kenneth Reitz
    I've recently become a little frustrated with Django as a whole. It seems like I can't get full control over anything. I love Python to death, but I want to be able (and free) to do something as simple as adding a css class to an auto-generated form. One MVC framework that I have really been enjoying working with is Grails (groovy). It has a FANTASTIC templating system and it lets you really have full control as you'd like. However, I am beyond obsessed with Python. So I'd like to find something decent and powerful written in it for my web application development. Any suggestions? Pylons maybe?

    Read the article

  • django return file over HttpResonse - file is not served correctly

    - by Tom Tom
    I want to return some files in a HttpResponse and I'm using the following function. The file that is returned always has a filesize of 1kb and I do not know why. I can open the file, but it seems that it is not served correctly. Thus I wanted to know how one can return files with django/python over a HttpResponse. @login_required def serve_upload_files(request, file_url): import os.path import mimetypes mimetypes.init() try: file_path = settings.UPLOAD_LOCATION + '/' + file_url fsock = open(file_path,"r") #fsock = open(file_path,"r").read() file_name = os.path.basename(file_path) mime_type_guess = mimetypes.guess_type(file_name) try: if mime_type_guess is not None: response = HttpResponse(mimetype=mime_type_guess[0]) response['Content-Disposition'] = 'attachment; filename=' + file_name response.write(fsock) finally: fsock.close() except IOError: response = HttpResponseNotFound() return response

    Read the article

  • Django queries: Count number of objects with FK to model instance

    - by Chris Lawlor
    This should be easy but for some reason I'm having trouble finding it. I have the following: App(models.Model): ... Release(models.Model): date = models.DateTimeField() App = models.ForeignKey(App) ... How can I query for all App objects that have at least one Release? I started typing: App.objects.all().annotate(release_count=Count('??????')).filter(release_count__gt=0) Which won't work because Count doesn't span relationships, at least as far as I can tell. BONUS: Ultimately, I'd also like to be able to sort Apps by latest release date. I'm thinking of caching the latest release date in the app to make this a little easier (and cheaper), and updating it in the Release model's save method, unless of course there is a better way. Edit: I'm using Django 1.1 - not averse to migrating to dev in anticipation of 1.2 if there is a compelling reason though.

    Read the article

< Previous Page | 71 72 73 74 75 76 77 78 79 80 81 82  | Next Page >