Search Results

Search found 8279 results on 332 pages for 'django permissions'.

Page 107/332 | < Previous Page | 103 104 105 106 107 108 109 110 111 112 113 114  | Next Page >

  • Creating a db driven primary navigation in django?

    - by Fedor
    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.

    Read the article

  • Using a backwards relation (i.e FOO_set) for ModelChoiceField in Django

    - by Bwmat
    I have a model called Movie, which has a ManyToManyField called director to a model called Person, and I'm trying to create a form with ModelChoiceField like so: class MovieSearchForm(forms.Form): producer = forms.ModelChoiceField(label='Produced by', queryset=movies.models.Person.producer_set, required=False) but this seems to be failing to compile (I'm getting a ViewDoesNotExist exception for the view that uses the form, but it goes away if I just replace the queryset with all the person objects), I'm guessing because '.producer_set' is being evaluated too 'early'. How can I get this work? here are the relevant parts of the movie/person classes: class Person(models.Model): name = models.CharField(max_length=100) class Movie(models.Model): ... producer = models.ForeignKey(Person, related_name="producers") director = models.ForeignKey(Person, related_name="directors") What I'm trying to do is get ever Person who is used in the producer field of some Movie.

    Read the article

  • After getting the 'It worked!' page with Djangoappengine, what do I do next?

    - by Jacques Bosch
    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.

    Read the article

  • How to generate a line break in Django template

    - by Iamamac
    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.

    Read the article

  • Django - Check users messages every request

    - by Hanpan
    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.

    Read the article

  • How to teach Django to non-web programmers? [closed]

    - by Greg
    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?

    Read the article

  • How to make form validation in Django dynamic?

    - by Oli
    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

    Read the article

  • Using Django.test.client to check template vars

    - by scott
    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??

    Read the article

  • How to make my view better to save Django

    - by user558251
    Hy guys sorry for this post but i need help with my application, i need optimize my view. I have 5 models, how i can do this? def save(request): # get the request.POST in content if request.POST: content = request.POST dicionario = {} # create a dict to get the values in content for key,value in content.items(): # get my fk Course.objects if key == 'curso' : busca_curso = Curso.objects.get(id=value) dicionario.update({key:busca_curso}) else: dicionario.update({key:value}) #create the new teacher Professor.objects.create(**dicionario) my questions are? 1 - How i can do this function in a generic way? Can I pass a variable in a %s to create and get? like this way ? foo = "Teacher" , bar = "Course" def save(request, bar, foo): if request post: ... if key == 'course' : get_course = (%s.objects.get=id=value) %bar ... (%s.objects.create(**dict)) %foo ??? i tried do this in my view but don't work =/, can somebody help me to make this work ? Thanks

    Read the article

  • django join querysets from multiple tables

    - by dana
    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?

    Read the article

  • Django: How to write the reverse function for the following

    - by ninja123
    The urlconf and view is as follows: url(r'^register/$', register, { 'backend': 'registration.backends.default.DefaultBackend' }, name='registration_register'), def register(request, backend, success_url=None, form_class=None, disallowed_url='registration_disallowed', template_name='registration/registration_form.html', extra_context=None): What i want to do is redirect users to the register page and specify a success_url. I tried reverse('registration.views.register', kwargs={'success_url':'/test/' }) but that doesn't seem to work. I've been trying for hours and can't get my mind around getting it right. Thanks

    Read the article

  • Django: auto minifying css/js files before release

    - by Dzida
    Hi, I have following case: I want to use uncompressed js/css files during development (to debug js for example) but on production I want to switch automatically to minified versions of that files. some simple solution is to put in your template: <script src="some_js.{% if not debug %}min.{% endif %}js".... but this require manully providing that such file exist and to do minifaction manullay after original file change. How do you accomplish this in your projects? Is there any tool for this?

    Read the article

  • Best way Implement "refferal links" in Django

    - by Murkin
    Intro I am working on an e-commerce website. And we want to add a feature where a user can refer others via a custom link e.g.: http://mysite.com/a1t2312 or http://mysite.com/?ref=a1t2312 (a1t231 being the referral code). A user following such a link, will navigate a few pages on the site. And if he reached the 'buy' page and purchases something - the original referrer will get a discount. The question is: What is the best method to track the referral code ? Put it in the user's cookies ? Stick it somehow into the session ? Other method ? Thanks

    Read the article

  • Need help optimizing this Django aggregate query

    - by Chris Lawlor
    I have the following model class Plugin(models.Model): name = models.CharField(max_length=50) # more fields which represents a plugin that can be downloaded from my site. To track downloads, I have class Download(models.Model): plugin = models.ForiegnKey(Plugin) timestamp = models.DateTimeField(auto_now=True) So to build a view showing plugins sorted by downloads, I have the following query: # pbd is plugins by download - commented here to prevent scrolling pbd = Plugin.objects.annotate(dl_total=Count('download')).order_by('-dl_total') Which works, but is very slow. With only 1,000 plugins, the avg. response is 3.6 - 3.9 seconds (devserver with local PostgreSQL db), where a similar view with a much simpler query (sorting by plugin release date) takes 160 ms or so. I'm looking for suggestions on how to optimize this query. I'd really prefer that the query return Plugin objects (as opposed to using values) since I'm sharing the same template for the other views (Plugins by rating, Plugins by release date, etc.), so the template is expecting Plugin objects - plus I'm not sure how I would get things like the absolute_url without a reference to the plugin object. Or, is my whole approach doomed to failure? Is there a better way to track downloads? I ultimately want to provide users some nice download statistics for the plugins they've uploaded - like downloads per day/week/month. Will I have to calculate and cache Downloads at some point? EDIT: In my test dataset, there are somewhere between 10-20 Download instances per Plugin - in production I expect this number would be much higher for many of the plugins.

    Read the article

  • Django populate select field based on model query

    - by Mike
    I have the following model class DNS(models.Model): domain = models.ForeignKey(Domain) host_start = models.CharField(max_length=150, blank=True, null=True) type = models.SmallIntegerField(max_length=1, default=0, choices=DNS_CHOICE) value = models.SmallIntegerField(max_length=3, default=0, blank=True, null=True) ip = models.IPAddressField(blank=True, null=True) host_end = models.ForeignKey("DNS", blank=True, null=True) other_end = HostnameField(max_length=150, blank=True, null=True) created = models.DateTimeField(auto_now_add=True) sticky = models.BooleanField(default=0) other = models.BooleanField(default=0) When I try to init a form with just foreignkeys on host_end.. it always shows all entries in the DNS table domain = Domain.objects.get(id=request.GET['domain'], user=request.user, active=1) form = DNSFormCNAME(initial={'ip': settings.MAIN_IP, 'type': request.GET['type'], 'host_end': DNS.objects.filter(domain=domain)}) I just want the zones that match that domain.. not all domains.

    Read the article

  • Is there a way to ignore Cache errors in Django?

    - by Josh Smeaton
    I've just set our development Django site to use redis for a cache backend and it was all working fine. I brought down redis to see what would happen, and sure enough Django 404's due to cache backend behaviour. Either the Connection was refused, or various other errors. Is there any way to instruct Django to ignore Cache errors, and continue processing the normal way? It seems weird that caching is a performance optimization, but can bring down an entire site if it fails. I tried to write a wrapper around the backend like so: class CacheClass(redis_backend.CacheClass): """ Wraps the desired Cache, and falls back to global_settings default on init failure """ def __init__(self, server, params): try: super(CacheClass, self).__init__(server, params) except Exception: from django.core import cache as _ _.cache = _.get_cache('locmem://') But that won't work, since I'm trying to set the cache type in the call that sets the cache type. It's all a very big mess. So, is there any easy way to swallow cache errors? Or to set the default cache backend on failure?

    Read the article

  • Django: ordering numerical value with order_by

    - by h3
    I'm in a situation where I must output a quite large list of objects by a CharField used to store street addresses. My problem is, that obviously the data is ordered by ASCII codes since it's a Charfield, with the predictable results .. it sort the numbers like this; 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21.... Now the obvious step would be to change the Charfield the proper field type (IntegerField let's say), however it cannot work since some address might have apartments .. like "128A". I really don't know how I can order this properly ..

    Read the article

  • Django display notifications by day

    - by dana
    hi guys, i have a notification list, and i want to order them by day, meaning, that i want to have in my notification list every day a title like 'Monday 16th od September' and the notifications for that day. I did not find anywhere how it should be done thanks a lot!

    Read the article

  • Django | How to pass form values to an redirected page

    - by MMRUser
    Here's my function: def check_form(request): if request.method == 'POST': form = UsersForm(request.POST) if form.is_valid(): cd = form.cleaned_data try: newUser = form.save() return HttpResponseRedirect('/testproject/summery/) except Exception, ex: # sys.stderr.write('Value error: %s\n' % str(ex) return HttpResponse("Error %s" % str(ex)) else: return render_to_response('index.html', {'form': form}, context_instance=RequestContext(request)) else: form = CiviguardUsersForm() return render_to_response('index.html',context_instance=RequestContext(request)) I want to pass each and every field in to a page call summery and display all the fields when user submits the form, so then users can view it before confirming the registration. Thanks..

    Read the article

< Previous Page | 103 104 105 106 107 108 109 110 111 112 113 114  | Next Page >