Re: Using a model method in ModelAdmin fieldsets
The better approach would be to specify a custom form in your ModelAdmin. This way your fieldset definition could include anything that's specified in your custom form. For Example: class SampleModel(models.Model): email = models.EmailField... firstname = models.CharField... class SampleForm(forms.ModelForm): lastname = form.CharField... class SampleModelAdmin(admin.ModelAdmin) fieldsets = (('General Info', {'fields' : ('email', 'firstname', 'lastname')}),) form = SampleForm You would just have to override save_model to ensure that it does the appropriate things with the additional fields. On Jan 7, 9:44 am, EagerToUnderstand wrote: > Thanks Karen & Daniel, > > I think your overiding approach will work. Thank you. > > Implemented a work around. I added extra fields (that persist my > method information) to my model that I update and save when I do a > listing. Price I pay is an extra database update each time the model > is getting listed. > Will see how it influence performance. > > Thank you for your replies. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Using a model method in ModelAdmin fieldsets
One more comment: You would also want to make sure that the init method of SampleForm populates the non-model fields (ie. lastname) with the correct values. class SampleForm(forms.ModelForm): lastname = form.CharField... def __init__(self, *args, **kwargs): super(SampleForm, self).__init__(self, *args, **kwargs) ... self.fields['lastname'].initial = ... On Jan 8, 3:14 am, Andy wrote: > The better approach would be to specify a custom form in your > ModelAdmin. This way your fieldset definition could include anything > that's specified in your custom form. > > For Example: > > class SampleModel(models.Model): > > email = models.EmailField... > firstname = models.CharField... > > class SampleForm(forms.ModelForm): > > lastname = form.CharField... > > class SampleModelAdmin(admin.ModelAdmin) > > fieldsets = (('General Info', {'fields' : ('email', 'firstname', > 'lastname')}),) > form = SampleForm > > You would just have to override save_model to ensure that it does the > appropriate things with the additional fields. > > On Jan 7, 9:44 am, EagerToUnderstand wrote: > > > Thanks Karen & Daniel, > > > I think your overiding approach will work. Thank you. > > > Implemented a work around. I added extra fields (that persist my > > method information) to my model that I update and save when I do a > > listing. Price I pay is an extra database update each time the model > > is getting listed. > > Will see how it influence performance. > > > Thank you for your replies. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Database connection closed after each request?
On Jul 24, 4:39 pm, James Bennett wrote: > Except this is what it turns into. So suppose a patch is added which > does nothing except keep the database connection open; well, that's > problematic because it means a server process/thread that's not > handling a request at the moment is still tying up a handle to a DB > connection. So somebody will say it'd be much better if Django > maintained a pool of connections independent of request/response > cycles, and just doled them out as needed. I think you're mixing 2 different things together: persistent connection & connection pooling. There's no reason that you can't have persistent connection without connection pooling. For connection pooling you can make an argument whether it belongs in an ORM or not (although SQLAlchemy supports connection pooling just fine) But on the other hand if all a user wants is simple persistent connection then it would seem logical for the ORM to provide that. Ideally Django should offer choices to users: if a user doesn't mind tearing down and building up a DB connection every time a request is processed, he could use non-persistent connection, but if he wants to save that time & reuse DB connection, he should be able to choose persistent connection. > if you've got enough traffic > through your app that the overhead of DB connections is problematic, > you should be using one of those tools. But this isn't about traffic at all. It's about latency, which has nothing to do with traffic. Amazon has done studies on the effects of response time. They varied the response times of their website and observed the resultant changes in user behavior. What they found is that for every 50ms increase in response time, the rate at which users order an item drops by 10%. Seen under this light, the additional 150ms latency resulting from non- persistent DB connection is huge - it implies almost 30% fewer customer orders. And it has nothing to do with traffic. I could be running a tiny e-commerce site. My traffic could be minimal. And I probably wouldn't have the expertise/time/money to run a pooling system for my tiny site. But I still wouldn't want to lose 30% of my orders just because I can't have persistent DB connections. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Database connection closed after each request?
On Jul 23, 10:50 pm, Glenn Maynard wrote: > In this case, that's a terrible-performance-by-default approach. > (It's also not a default, but the only behavior, but I'll probably > submit a patch to add a setting for this if I don't hit any major > problems.) Agreed. Please share any patches you have. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Database connection closed after each request?
On Jul 24, 8:54 pm, Alex Gaynor wrote: > "Seen under this light, the additional 150ms latency resulting from non- > persistent DB connection is huge - it implies almost 30% fewer > customer orders. And it has nothing to do with traffic." > > I'd just like to take a moment to point out that that simply *cannot* > be, else the only logical conclusion would be that .5s of latency > results in 0 sales, which plainly makes no sense. Actually it doesn't mean that at all. First of all, the 10% decrease in order for each additional 50ms increase in latency is *multiplicative*, NOT additive. For the 150ms increase in latency that non-persistent connection costs you, the decrease in order is 1 - 0.9^3 = 27.1%, hence I wrote "almost 30%" Hence for a 0.5s increase in latency, *if the relationship still holds over a range that big*, the corresponding drop in order would be 1- 0.9^10 = 65%. Which isn't exactly impossible. But my guess is for increase in latency that large, the original "50ms results in 10% drop" relationship will no longer holds. Regardless, the point is that latency is a big deal whether your site is large or small. Even a small latency increase can have a big impact on user behavior. Telling every mom & pop site owner out there "Go set up pgpool or hack the Django signal handler if you don't want high latency" is not very user friendly. Especially when the solution (providing optional persistent DB connection) is relatively simple. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to scale out django apps?
Tim, Thanks for the helpful answers. As for specific details about my app, right now I'm still in the design phase. It will start small, but hopefully it will get popular quickly. So I don't know how big the Db will be or how many users will there be. What I'm trying to do is to make sure there is a graceful scale out path should such a need arise. Some answers to your questions: > are you bringing back huge datasets or just small sub-slices of your data? Small > are you updating large swaths of data at a time, or are you just updating single records most of the time? Mostly single records > are just a few select users doing the updating, and all the rest of your users are doing piles of reads? Most users will do both reads and writes. The usage pattern is not unlike facebook status update, where most users will both update status and read status frequently. > can you partition by things that totally do not relate, such as by customer, so each customer can have their own instance that then gets put wherever your admins define letting DNS balance the load? (a'la BaseCamp's customername.basecamp.com) App is for general users, anyone can sign up for free. So I doubt this would work. > can you tolerate replication delays? what time-frame? (sub-second? async taking up to 30 minutes? a whole day?) Probably not. If a user updates her own status, she should be able to see that updates immediately. Otherwise she'd think the site is not working. Is there any plan to support multiple connections? Sharding is a very common techniques used in many places. I know in theory with a big server and huge SAN disk array a single database could support many users, but it's a lot cheaper to use multiple commodity servers instead. And even with a huge budget sooner or later the scale up approach will stop working. On Apr 13, 6:51 am, Tim Chase wrote: > > Recently I found out Django doesn't support multiple databases. That's > > quite surprising. > > > Given that limitation, how do you scale out a Django app? > > Depends on where your bottleneck(s) is/are. It also depends > heavily on your read/write usage pattern. If you're truly > experiencing a stenosis of the database connection, you have > several options, but most of them reside in domain specific tuning. > > > Without multi-DB support, most of the usual techniques for scaling out > > such as: > > - DB sharding > > - functional partitioning - eg. separate DB servers for user > > profiles, orders, and products > > would be infeasible with django. > > Sharding and functional partitioning don't yet exist in stock > Django. There's a GSoC project that may make some headway on > "multiple database support", but I've not heard anything further > on the Django Developers regarding that. > > > I know replication is still available. But that still means all data > > must fit in 1 server. > > Well, with bountiful storage using things like AoE, SAS, SAN, FC, > etc, having "all the data fit in one server" isn't a horrible > issue. And with 1TB drives on the market, fitting multiple TB in > a single machine isn't a disastrous idea. If you have more data > than will fit in a single machine, you have a lot of other issues > and will likely have to get very specific (and likely expensive > ;-) help. > > > Also replication isn't going to help update performance. > > This goes back to my "read/write usage pattern" quip...if you > have a high volume of reads, and a low volume of writes, > replication is one of the first tools you reach for. However, > with a high volume of writes, you've entered the realm of "hard > problems". Usually if you app reaches this volume of DB traffic, > you need a solution specialized to your domain, so stock Django > may not be much help. Given that you've not detailed the problem > you're actually having (this is where profiling comes in), it's > hard to point much beyond the generic here. So answers to some > questions might help: > > - are you bringing back huge datasets or just small sub-slices of > your data? > > - are you updating large swaths of data at a time, or are you > just updating single records most of the time? > > - are just a few select users doing the updating, and all the > rest of your users are doing piles of reads? > > - how big is this hypothetical DB of yours? > > - can you partition by things that totally do not relate, such as > by customer, so each customer can have their own instance that > then gets put wherever your admins define letting DNS balance the > load? (a'la BaseCamp's customername.basecamp.com) > > - can you tolerate replication delays? what time-frame? > (sub-second? async taking up to 30 minutes? a whole day?) > > - how readily can you cache things to prevent touching the > database to begin with? Can you cache with an HTTP proxy > font-end for repeated pages? Can you cache datasets or other > fragments with memcached? If your web-app follows good design, > any GET can be cache
Re: How to set up MySQL replication on Django?
Great. Thanks. On Apr 19, 7:59 am, Alex Koshelev wrote: > There is an existing production-ready application [1] that allows you > to use MySQL replication facilities. It is formed as django database > backend with some additional functional. > > We use it for our high-load Django powered content services. > > [1]:http://softwaremaniacs.org/soft/mysql_replicated/en/ > > On Sun, Apr 19, 2009 at 3:55 PM, Continuation wrote: > > > In the Django Book, it is stated that: > >http://www.djangobook.com/en/2.0/chapter12/ > > > "As you need more database performance, you might want to add > > replicated database servers. MySQL includes built-in replication" > > > But how exactly would MySQL replication work with Django? > > > According to MySQL doc: > >http://dev.mysql.com/doc/refman/5.1/en/replication-solutions-scaleout... > > > "Change the implementation of your database access to send all writes > > to the master, and to send reads to either the master or a slave." > > > So it is the application's responsibility to direct DB writes to > > master & reads to either master or slave. But since Django doesn't > > support multiple database access, this wouldn't work. > > > So what does the Django book mean by "you might want to add replicated > > database servers" if Django doesn't support accessing replicated > > databases? > > > Does anyone have django setup that uses replicated DB? would love to > > hear your experiences. > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Hidden field in Admin without label
Hello Pierre. I recently came across the exact same problem (and for the exact same reason) I don't think my solution was any less ugly that yours. I modified fieldset.html to look for a specific fieldset name. Anything in that fieldset is displayed in a manner which honors the hidden field property. (so still a hack!) Andy On May 7, 10:01 am, PierreR wrote: > Thanks for your reply. > > My intention is to use this field as a version/timestamp to implement > a form of optimistic locking. I need to receive it back from the user > through a form and check it against the current version/timestamp of > the updated record. > > I don't think "exclude" will work for me. > > > > > Hmm. Does the field need to be in the form at all? You could just add > > it to the 'exclude' tuple in the ModelAdmin declaration, then it won't > > show up. > > -- > > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is there a version of @login_required that requires the user to log in as a specific user?
On May 24, 9:54 pm, Brian Neal wrote: > On May 24, 6:50 pm, Continuation wrote: > > > For example, I have a view edit_profile that edits a user's profile. > > Obviously I want to make sure that each user can edit his own profile > > only. > > > So before the profile of user A is being edited by edit_profile, I > > want to make sure the current user is logged in as user A. > > > Is there a decorator that can do that? > > > Is there a decorator similar to @login_required that requires not only > > the user to be logged in, but also that he needs to be logged in as a > > specific user (user A in the above example)? > > Well, typically you don't worry about that. If a user is requesting to > edit a profile, you simple pull up that user's profile. But how do I stop user A from trying to edit the profile of user B? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Newbie needs help
Hello, I am new to Django and Python but am determined to learn. I am creating a page that asks for some user input. My model looks like this: from django.db import models from django.forms import ModelForm floor_plan_choices = ( ('A', 'Square'), ('B', 'Rectangular'), ('C', 'Round'), ) direction_choices = ( ('360', '360'), ('270', '270'), ('180', '180'), ('90', '90'), ) class Customer(models.Model): date_stamp = models.DateTimeField(auto_now_add=True) order_number = models.PositiveIntegerField(editable=False) first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=40) email = models.EmailField() email_conf = models.EmailField(verbose_name='Confirm Email') year_built = models.PositiveIntegerField() period = models.PositiveIntegerField(editable=False) direction = models.DecimalField(max_digits=5, decimal_places=2, choices=direction_choices) floor_plan = models.CharField(max_length=2, choices=floor_plan_choices) def __unicode__(self): return u'%s %s' % (self.first_name, self.last_name) class CustomerForm(ModelForm): class Meta: model = Customer And my view looks like this: from django.shortcuts import render_to_response from django.http import HttpResponseRedirect from newsite.order.models import CustomerForm def order(request): if request.method == 'POST': form = CustomerForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/order_complete/') else: form = CustomerForm() return render_to_response('order.html', {'form': form}) def order_complete(request): return render_to_response('order_complete.html') I would like to set the order_number in my model to be equal to the automatically assigned ID plus 10,000. Can anybody tell me how to achieve this? Thanks for your help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to modify and object before saving it in ModelForm [was] Newbie needs help
Thanks Kenneth. I'll check out the link and use better subject lines in the future...unless you want to send a donation! On May 30, 1:38 am, Kenneth Gonsalves wrote: > On Saturday 30 May 2009 12:47:27 Andy wrote: > > > I would like to set the order_number in my model to be equal to the > > automatically assigned ID plus 10,000. Can anybody tell me how to > > achieve this? > > check out commit=False in this > document:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav... > > And always put a proper subject line - your subject line looks like you are > soliciting donations ;-) > -- > regards > kghttp://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Confirm email by matching on form
I have a form with an email field and email confirmation field. I want to check the form input to make sure the two fields match. So far I can get the error message 'Email addresses do not match.' to display, but if they do match I am getting an error 'InterfaceError at /order/ Error binding parameter 5 - probably unsupported type' Here is my code: #models from django.db import models from django import forms from django.forms import ModelForm class Customer(models.Model): date_stamp = models.DateTimeField(auto_now_add=True) order_number = models.PositiveIntegerField(editable=False) first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=40) email = models.EmailField() email_conf = models.EmailField(verbose_name='Confirm Email') year_built = models.PositiveIntegerField() period = models.PositiveIntegerField(editable=False) direction = models.CharField(max_length=20, choices=direction_choices) floor_plan = models.CharField(max_length=2, choices=floor_plan_choices) def __unicode__(self): return u'%s %s' % (self.first_name, self.last_name) class CustomerForm(ModelForm): class Meta: model = Customer def clean_year_built(self): year = self.cleaned_data['year_built'] if year < 1800: raise forms.ValidationError("Please enter a year between 1800 and 2020.") if year > 2020: raise forms.ValidationError("Please enter a year between 1800 and 2020.") return year def clean_email_conf(self): cleaned_data = self.cleaned_data email = cleaned_data.get("email") email_conf = cleaned_data.get("email_conf") if email and email_conf: if email != email_conf: raise forms.ValidationError("Email addresses do not match.") return cleaned_data #views from django.shortcuts import render_to_response from django.http import HttpResponseRedirect from newsite.order.models import Customer, CustomerForm def order(request): if request.method == 'POST': form = CustomerForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/order_complete/') else: form = CustomerForm() return render_to_response('order.html', {'form': form}) def order_complete(request): return render_to_response('order_complete.html') -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=.
Re: Confirm email by matching on form
I should say that I am using Django 1.1.1, Python 2.5 and sqlite3. Thanks for your help. On Nov 15, 9:29 am, Andy wrote: > I have a form with an email field and email confirmation field. I > want to check the form input to make sure the two fields match. So > far I can get the error message 'Email addresses do not match.' to > display, but if they do match I am getting an error 'InterfaceError > at /order/ > Error binding parameter 5 - probably unsupported type' Here is my > code: > > #models > from django.db import models > from django import forms > from django.forms import ModelForm > > class Customer(models.Model): > date_stamp = models.DateTimeField(auto_now_add=True) > order_number = models.PositiveIntegerField(editable=False) > first_name = models.CharField(max_length=30) > last_name = models.CharField(max_length=40) > email = models.EmailField() > email_conf = models.EmailField(verbose_name='Confirm Email') > year_built = models.PositiveIntegerField() > period = models.PositiveIntegerField(editable=False) > direction = models.CharField(max_length=20, > choices=direction_choices) > floor_plan = models.CharField(max_length=2, > choices=floor_plan_choices) > > def __unicode__(self): > return u'%s %s' % (self.first_name, self.last_name) > > class CustomerForm(ModelForm): > > class Meta: > model = Customer > > def clean_year_built(self): > year = self.cleaned_data['year_built'] > if year < 1800: > raise forms.ValidationError("Please enter a year > between 1800 and > 2020.") > if year > 2020: > raise forms.ValidationError("Please enter a year > between 1800 and > 2020.") > return year > > def clean_email_conf(self): > cleaned_data = self.cleaned_data > email = cleaned_data.get("email") > email_conf = cleaned_data.get("email_conf") > if email and email_conf: > if email != email_conf: > raise forms.ValidationError("Email addresses > do not match.") > return cleaned_data > #views > from django.shortcuts import render_to_response > from django.http import HttpResponseRedirect > from newsite.order.models import Customer, CustomerForm > > def order(request): > if request.method == 'POST': > form = CustomerForm(request.POST) > if form.is_valid(): > form.save() > > return HttpResponseRedirect('/order_complete/') > else: > form = CustomerForm() > > return render_to_response('order.html', {'form': form}) > > def order_complete(request): > return render_to_response('order_complete.html') -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=.
Re: Confirm email by matching on form
Thank you all for your replies. Karen, both good points. pjrharley, I agree with Dennis. If the user is required to re-type their email address, then that in combination with Django's simple built in email validation should be sufficient. I am using a ModelForms right now. If I remove email_conf from my model, do I add it to the ModelForm, place it in the html form or create a new form to handle it? I guess I'm still a little unsure as to when to use Forms over ModelForms. On Nov 15, 3:51 pm, Dennis Kaarsemaker wrote: > On zo, 2009-11-15 at 13:38 -0800, pjrhar...@gmail.com wrote: > > > Also, I have an even simpler suggestion. Don't make the user confirm > > their email. I'm getting fed up with seeing this on forms all over the > > web when it serves no purpose at all. You confirm a password because > > you can't read it back. You don't ask them to confirm every other > > field do you? > > Where I work, we require users to confirm their e-mail address as well > and for a very good reason: too often do people make typos there. For > fields like 'your name' that's not too important but we send them e-mail > with important details and this is an easy measure to make sure less of > this mail bounces :) > > -- > Dennis K. > > The universe tends towards maximum irony. Don't push it. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=.
Difficulty using anchor tags in templates
I have a model named Articles with title and content fields. Each page of my site should display a list of the titles, linked with anchor tags to the corresponding area of the Resources page which displays all the titles and content. I am having trouble figuring out how to pass the #title info. I've read a previous post:http:// groups.google.com/group/django-users/browse_thread/thread/ bf5bae5b333aae/b8627d237d34fd69?lnk=gst&q=anchor+tag#b8627d237d34fd69, but am still struggling. Views(snippet): articles = Context({'articles': Articles.objects.all()}) def index(request): return render_to_response('index.html', articles) def resources(request): return HttpResponseRedirect('/resources/') Base Template(snippet): Resources {% for articles in articles %} {{ articles }} {% endfor %} I am getting a 'too many redirect' error with this code. Can anybody help me with this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Difficulty using anchor tags in templates
Hmm, still not clear. My url is simply this: (r'^resources/$', views.resources) I have read that I need to use HttpResponseRedirect to make use of #anchor tags. Is this not the case? Thanks for your help! On Nov 29, 8:38 am, rebus_ wrote: > 2009/11/29 Andy : > > > > > > > I have a model named Articles with title and content fields. Each > > page of my site should display a list of the titles, linked with > > anchor tags to the corresponding area of the Resources page which > > displays all the titles and content. I am having trouble figuring out > > how to pass the #title info. I've read a previous post:http:// > > groups.google.com/group/django-users/browse_thread/thread/ > > bf5bae5b333aae/b8627d237d34fd69?lnk=gst&q=anchor+tag#b8627d237d34fd69, > > but am still struggling. > > > Views(snippet): > > articles = Context({'articles': Articles.objects.all()}) > > def index(request): > > return render_to_response('index.html', articles) > > def resources(request): > > return HttpResponseRedirect('/resources/') > > > Base Template(snippet): > > > > Resources > > > > {% for articles in articles %} > > > target="_blank"> > > {{ articles }} > > {% endfor %} > > > > > > > I am getting a 'too many redirect' error with this code. Can anybody > > help me with this? > > With assumption you have set your url like: > > url(r'^resources/$', 'resources', name='resources') > > each time you open "resources" view you would get redirected to the > "resources" view and you have endless loop, which browsers would > terminate after certain number of repetitions. > > resources view should return html page with titles and content rather > then redirect to it self. > > Basically, when you click on "/some/page/#fid", view which handles > /some/page/ url should return HTML page, and if there is a fragment id > ("#fid" in this case) in that page your browser should position your > page on that fragment id (if possible). > > Hope i didn't overcomplicated this :) > > Davor -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Difficulty using anchor tags in templates
Fantastic! I think I was overthinking my problem. Thanks a lot! On Nov 29, 10:36 am, rebus_ wrote: > BTW here is an example: > > When you click this > link:http://en.wikipedia.org/wiki/Fragment_identifier#Processing > > your browser will open uphttp://en.wikipedia.org/wiki/Fragment_identifierpage > and then scroll > down to the Processing title without wikipedia even knowing that you > specifically want to see that part of the page, it will just send you > the page and let your browser worry about scrolling. > > Also i apologize, since English is not my native language i might have > trouble explaining some thing with it :) > > Davor -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to choose one row of data
This is a very beginner question: Say a user has just filled out a form and hit the submit button. They are redirected to an order confirmation page. How can I retrieve the one row of data the user just submitted and display it on the order confirmation page? Here is my simple View so far, but it currently displays all the user inputed data, not the specific row the user just entered: articles = Context({'articles': Articles.objects.all()}) order_info = Context({'order_data': Order_Info.objects.all()}) def order(request): if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/order_complete/') else: form = OrderForm() return render_to_response('order.html', {'form': form}, articles) def order_complete(request): return render_to_response('order_complete.html', order_info, articles) Thanks for your help! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to choose one row of data
Thanks for the response Shawn. I have done what you suggested, assigning a variable named order_info and can use it if I use render_to_response in my order view. But I want to use HttpResponseRedirect after the form is saved. I'm thinking I need to get the order_info variable into my order_complete view. How can I do this? articles = Context({'articles': Articles.objects.all()}) def order(request): if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): current_order = form.save() order_info = Context({'order_info': current_order}) return render_to_response('order_complete.html', order_info, articles) #this works return HttpResponseRedirect('/order_complete/') #but this is what I want to use else: form = OrderForm() return render_to_response('order.html', {'form': form}, articles) def order_complete(request): #how can I put order_info here? return render_to_response('order_complete.html', order_info, articles) On Dec 9, 8:10 pm, Shawn Milochik wrote: > If you assign the output of the save() method, you'll get the created object. > > Instead of: > > form.save() > > do: > > current_order = form.save() > > Then you can do whatever you like with current_order, which will be an > instance of whatever the class 'meta' is of your OrderForm, assuming that > OrderForm is a forms.ModelForm. > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to choose one row of data
Thank you DR. For other newbies out there I changed my views to this and it worked great: articles = Context({'articles': Articles.objects.all()}) def order(request): if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): current_order = form.save() order_info = Context({'order_info': current_order}) request.session['order_info'] = order_info return HttpResponseRedirect('/order_complete/') else: form = OrderForm() return render_to_response('order.html', {'form': form}, articles) def order_complete(request): order_info = request.session['order_info'] return render_to_response('order_complete.html', order_info, articles) On Dec 11, 9:30 am, Daniel Roseman wrote: > On Dec 11, 3:13 pm, Andy wrote: > > > > > > > Thanks for the response Shawn. I have done what you suggested, > > assigning a variable named order_info and can use it if I use > > render_to_response in my order view. But I want to use > > HttpResponseRedirect after the form is saved. I'm thinking I need to > > get the order_info variable into my order_complete view. How can I do > > this? > > > articles = Context({'articles': Articles.objects.all()}) > > > def order(request): > > if request.method == 'POST': > > form = OrderForm(request.POST) > > if form.is_valid(): > > current_order = form.save() > > order_info = Context({'order_info': current_order}) > > return render_to_response('order_complete.html', > > order_info, > > articles) #this works > > return HttpResponseRedirect('/order_complete/') > > #but this is what I > > want to use > > else: > > form = OrderForm() > > > return render_to_response('order.html', {'form': form}, articles) > > > def order_complete(request): #how can I put order_info here? > > return render_to_response('order_complete.html', order_info, > > articles) > > The order_complete view needs some way of knowing about the object > you've just created. Obviously, it's in the database, so all you need > to give that view is some way to identify it - eg by the id field. > > So you'll need to either pass it as a URL parameter to the > order_complete view: > return HttpResponseRedirect('/order_complete/%s/' % > current_order.id) > > or put it into the session when you save the form, and get it out > again in the order_complete view. Obviously if there's any personal > info involved, you should not use the first method, or at least add > some extra authentication. > -- > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to choose one row of data
Tom - DR's method is simple and effective, but I'm guessing you say it's the worst way because it creates an unnecessary database request. Is this a correct assumption? If not, please explain. On Dec 11, 10:58 am, Tom Evans wrote: > On Fri, Dec 11, 2009 at 4:44 PM, Andy wrote: > > Thank you DR. For other newbies out there I changed my views to this > > and it worked great: > > > articles = Context({'articles': Articles.objects.all()}) > > > def order(request): > > if request.method == 'POST': > > form = OrderForm(request.POST) > > if form.is_valid(): > > current_order = form.save() > > order_info = Context({'order_info': current_order}) > > request.session['order_info'] = order_info > > return HttpResponseRedirect('/order_complete/') > > else: > > form = OrderForm() > > > return render_to_response('order.html', {'form': form}, articles) > > > def order_complete(request): > > order_info = request.session['order_info'] > > return render_to_response('order_complete.html', order_info, > > articles) > > This is the worst way to pass state. The state should be passed via > the user, rather than storing it in the session. Your view should look > something like this: > > def order(request): > if request.method == 'POST': > form = OrderForm(request.POST) > if form.is_valid(): > order = form.save() > return HttpResponseRedirect(reverse('order_complete', args=[order.id])) > else: > form = OrderForm() > > return render_to_response('order.html', {'form': form}, articles) > > def order_complete(request, order_id=None): > order = get_object_or_404(Order, id=order_id) > return render_to_response('order_complete.html', {'order': order}, articles) > > Cheers > > Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Horizontal database sharding implemented by model sharding?
What is the best way to implement horizontal database sharding through Django? For example, say I have a class Note. I want to shard the database table Note into N shards based on the Note author's id - author.id % N 1) Should I shard the class Note into N corresponding classes - Note0, Note1, Note2, etc? Is that the best way to implement horizontal database sharding? 2) Normally I'd have to type out by hand the class definitions of those N classes and put them in models.py: class Note0(models.Model): ... class Note1(models.Model): ... class Note2(models.Model): ... Is there a way to generate these class definitions programatically without having to type out the N model definitions one by one? 3) When I want to store a Note into the database or to retrieve a Note from the db for a user, I'd do something like: shard_id = user.id % N And then go to the appropriate Note model based on shard_id. So if shard_id is 5 I'd deal with the model Note5. How do I select the correct Note model based on shard_id in runtime? How do you implement horizontal sharding in Django? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Possible to create models programatically?
I have N models that are identical except the model names (i.e. they all have the same attributes, methods): MyModel0, MyModel1, MyModel2, ... Normally I'd need to type out the model definitions for those N models by hand inside models.py. Is there a way to generate the N model definitions programatically instead of manually? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Possible to create models programatically?
> > I'm not completely sure what you're trying to do, but I have a blog > entry on creating temporary models programmatically - it might help > you:http://blog.roseman.org.uk/2010/04/13/temporary-models-django/ What I'm trying to do is to shard my database horizontally. For example say I have a model Tweet and I want to shard it into N tables using the modulo N of the user.id So now I have N different models of Tweet: Tweet0, Tweet1, Tweet2, ... each has the same structure, differing only in names. I could type out the N models by hand: class Tweet0(models.Model): content = models.CharField(max_length=140) datetime = models.DateTimeField() ... class Tweet1(models.Model): content = models.CharField(max_length=140) datetime = models.DateTimeField() ... class Tweet2(models.Model): content = models.CharField(max_length=140) datetime = models.DateTimeField() ... And I'd have to repeat that N times. Just wanted to see if there's a way to generate those N models programmatically (perhaps using a for loop) instead of typing them out manually. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Possible to create models programatically?
> > Why not use the facilities for sharding that are built in? > > Database routers [1] are designed to allow you to have a single model > definition, but decide which database connection is used at runtime > based on properties of the objects involved. > > [1]http://docs.djangoproject.com/en/dev/topics/db/multi-db/#automatic-da... > I must have misunderstood the database routers then. >From the documentation: "db_for_read(model, **hints) Suggest the database that should be used for read operations for objects of type model." I thought that means that all objects of type model must be routed to the same database. Could you give me an example of a database router that would - - first look at the type of the object, if it's of the type Tweet then look at the userid of the Tweet's author, take a modulo N of the userid, and then routes to DB0 if the modulo is 0, DB1 if the modulo is 1, etc? Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: scaling my site
I'd stay away from Amazon if like you said money is a concern. Amazon web services are extremely overpriced. For the same amount of money you'd be able to get much better performance by renting a dedicated server or even a VPS. Also if you're running databases then IO performance is critical. The disk performance of S3 is poor. On Jul 23, 3:43 pm, Tony wrote: > I have just about finished all the logic for my site. In short, I > need the site to be pretty fast and a good amount of database storage > with the possibility of getting more in the future if and probably > when I need it. Right now I am just testing my website on my computer > with Django, (mod_swgi) apache and postgresql. I should also mention > I don't have the money right now to buy my own servers so I've been > looking into Amazon S3 and the computing cloud, EC2 but this is my > first time doing something like this so I don't know too much about > these things. Anyway, I'm looking for advice on the best way to set > this website up and I am leaning toward using amazon's features, but I > really need a lot more insight on how all that works. What database > server should I use? How does S3 and EC2 work? Should i use a web > host like web-lackey.com or something? I'm a little unaware on how to > put something into production and how everything connects. I accept > and appreciate any advice on the matter. > Thanks, > Tony -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to use the Database Router?
I'm trying to shard my database horizontally. In another thread (http://groups.google.com/group/django-users/ browse_thread/thread/2748cdf205b5cf3e/ e8fe5087748d3c43#e8fe5087748d3c43) I was told it's best to use the Database Router to implement horizontal sharding. But I can't figure out how to use the Database Router to do what i want. The documentation doesn't contain a lot of info either. I have a model "Tweet". What I'd like to do is to shard Tweet into N different databases/ tables. When I need to read/write a Tweet object, I want to look at the Tweet author's userid, take modulo N of the id, and then depending on the result, route the operation to one of the N databases/tables. Is it possible to do that using the Database Router? Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to use the Database Router?
> Ah - this is possibly the source of confusion. Django's Routers can > shard to different databases, but not to different tables in the same > database. > > Why do you want to shard into different *tables*? The usual > interpretation of sharding (at least, the usual interpretation that > *I'm* familiar with) is to shard into different *databases*. I'm not > sure I see what you gain by using different tables in the same > database. > I probably didn't make it clear. I used the term "databases/tables" because (to me) if those tables lives in different databases then they are different tables. Anyway let me rephrase. I have a model "Tweet". I want to shard it into N databases based on the modulo N of the Tweet's author's id. So each database would have a table "Tweet" with the exact same structure. How do I do that with the Database Router? Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to use the Database Router?
> The db_for_read() and db_for_write() methods accept a model, and > usually a hint. If provided, the hint will be the instance the > database operation is acting on (or an instance related to the > operation). These methods return the alias of the database that should > be used to perform the read/write operation. > > To shard based on model properties, you inspect the hint object, and > use the details of that object to determine which database alias > should be used. The db_for_read() and db_for_write() methods will have > the same implementation, returning an alias that is computed based on > the modulo of the object 'owner', or whatever sharding behavior your > want to implement. Can you give me some examples of how to use hint and how to apply db_for_read() to a specific model type? I read the documentation but it contains very little information in those areas. Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to limit entries from each user to a specific number N (N > 1)?
I have an application that's similar to the typical Q&A system. A user asks a question. other users submit answers to that question: - Each user is allowed to submit up to N answers to each question, where N > 1 (so, say each user can submit no more than 3 answers to each question) - A user can edit his existing answers, or submit new answer(s) if he hasn't already reached his limit. It's straightforward to do this if each user is allowed only 1 answer - just do: unique_together = (("user.id", "question_id"),) But in case of N>1, what is the best way to implement this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How long do objects live?
When I create an object in Django, how long does it live? When Django finishes responding to a HTTP request, the Python process lives on to serve the next request. Does that mean all those objects that were created would continue to hang around? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Any job queue systems that integrates with Django & allow scheduling jobs by date?
I have a Django application. One of my models looks like this: class MyModel(models.Model): def house_cleaning(self): // cleaning up data of the model instance Every time when I update an instance of MyModel, I'd need to clean up the data N days later. So I'd like to schedule a job to call this_instance.house_cleaning() N days from now. Is there any job queue that would allow me to: - Integrate well with Django - allow me to call a method of individual model instances - Only run jobs that are scheduled to run today - Ideally handle failures gracefully Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?
I have a model Tweet that I'd like to shard horizontally based on the tweet author's id. class Tweet(models.Model): author_id = models.IntegreField() text = models.TextField() Let's say I set up 3 databases: shard0, shard1, shard2 I'd like to take the tweet author's id, do a modulo 3 and use the result to determine which shard a tweet should be located in. If I understand the documentation correctly, I'd do something like: class TweetRouter(object): N = 3 def db_for_read(self, model, **hints): if model.__name__ == "Tweet" and hints['instance'].author_id % N == 0: return 'shard0' if model.__name__ == "Tweet" and hints['instance'].author_id % N == 1: return 'shard1' if model.__name__ == "Tweet" and hints['instance'].author_id % N == 2: return 'shard2' return None A couple of questions: - Did I use the argument **hints correctly? I'm not entirely sure - How is auto-increment PK being handled in a horizontal sharding scenario like this? Say I have 3 tweets with 3 author_id: 0, 1, 2 Those 3 tweets will live in 3 separate databases. Each of them will get an auto-increment PK assigned by its database. Since they all live in different databases, potentially they could all get the same PK. Does that mean if I shard a model horizontally I could get into a situation where different model instances could have the same PK? How is this being handled? Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?
On Aug 19, 9:28 am, Russell Keith-Magee wrote: > You've got the right idea, but the implementation you provide probably > won't be comprehensive enough in practice. The hint is any extra > information that will help you determine the right database to use; > there's no guarantee that the instance hint will exist, or if it does, > that it will be an instance of Tweet. For example, when you create a > tweet, you won't have an instance -- and even if you did, you won't > have an author_id -- but you still need to nominate a write database > in order to save the instance. I'm not sure I understand: I thought hints will always contain the instance that is to be read or written. You're saying that's not the case? Under what circumstances will hints *not* contain the instance? In your example, I'd only want to write to the database when I'm ready to save a tweet. By that time a tweet instance would be in existence and that it would have an author_id, correct? So I don't understand your example. Did I miss something? Please elaborate. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?
On Aug 19, 9:03 pm, Russell Keith-Magee wrote: > As for the instance not existing: Consider the following queries: > > MyModel.objects.filter(foo=bar) > > or > > MyModel.objects.update(foo=bar) > > These are read and write queries respectively, but neither has any > meaningful concept of a current "instance". OK, now I see the issue. I'd need to do queries like this one: Tweet.objects.filter(author_id=123) Now like you said there isn't any current instance to speak of. However since I'm retrieving tweets from a specific author it is very clear which shard this query should go to as tweets are sharded by author_id. So is there any way to write the database router to route the above query? > If you think that Django isn't providing > sufficient information to implement a specific routing scheme, make > your case and we will see about adding whatever extra information may > be required. The issue with using only "instance" as a hint is that in almost all cases of database reads there isn't any instance to speak of at the time the query is being issued. After all the very purpose of a database read is to retrieve the instance! The above example of: Tweet.objects.filter(author_id=123) represents pretty much the most common scenario for database sharding. I'd think it's important for Django's multidatabase function to be able to handle a case like that. Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How does Django handle auto-increment PK when a model is sharded horizontally into multiple databases?
On Aug 20, 10:04 pm, Russell Keith-Magee wrote: >Of course, given that you know your sharding scheme, you could use the >router directly. > >Tweet.objects.using(router.db_for_read(Tweet, author=a)).filter(author_id=a) Ah Thanks. This is what I need. > You won't get any argument from me. What's missing is a clear > suggestion on how we can encompass this problem in the general case. > Suggestions are welcome. One suggestion I have is that any arguments in filter() should also be passed as part of the hints dictionary to the database router. The arguments in filter() should be enough information to determine which shard to select in most cases. So in the above example: Tweet.objects.filter(author_id=a) The keyword:value pair {'author_id': a} should be added to the hints that got passed to the database router. This achieves basically the same results as doing Tweet.objects.using(router.db_for_read(Tweet, author_id=a)).filter(author_id=a) But it doesn't require going through the entire codebase and modifying every single queryset so it's less prone to error and more DRY. I have another use case where I want to shard by primary pk which is an auto-increment. I have this model: class Auction(models.Model): seller_id = models.IntegerField() text = models.TextField() price = models.DecimalField() The PK of Auction is the auto-increment "id" field. Say I divide Auction into 3 shards and set up each shard so that the auto-increment id's don't collide. When I first create and save a new auction, it doesn't have an "id", so I just want to randomly pick a shard to save to: def db_for_write(self, model, **hints): if model.__name__ == "Auction" and 'instance' not in hints: return random.choice(['shard1','shard2', 'shard3']) Would the above work? Also how random is random - would I get a uniform distribution of records among the shards? Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Possible to do location detection?
I'd like to detect the location of each user and then set the default language and location for him accordingly. The homepage would also be tailored to each location (country and city). Can anyone share information on how to do that with Django? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
save() isn't thread-safe?
In this presentation save() is described as not thread-safe and update() is recommended to be used instead of save(): http://www.slideshare.net/zeeg/db-tips-tricks-django-meetup (page 2, 3, 4) Is it true that save() is not thread-safe? How is it not? Should I avoid using save() and use update() instead? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to store and retrieve objects to/from session?
I know I can store simple key/value pairs to session. Is it possible to store entire objects to session? I want to enable un-logged-in users to submit form data. After the form is submitted, I want to store the form data in session and then redirect the user to sign-in. After they sign in, I'd retrieve the stored form data from session and save it to database. For example: if request.method == 'POST': form_object = CommentForm(request.POST) Now if the user is not signed in, I want to save form_object to session, and later retrieve it from session after the user has signed in. Is there a way to save entire objects to session? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ANN: PyMySQL 0.3
Pete, Would you recommend PyMySQL for production use? Which parts of Django do I need to modify in order to use it with PyMySQL instead of MySQLdb? Thanks. On Sep 3, 2:07 pm, Pete Hunt wrote: > I’m proud to announce the release of PyMySQL 0.3. For those of you > unfamiliar with PyMySQL, it is a pure-Python drop-in replacement for > MySQLdb with an emphasis on compatibility with MySQLdb and for various > Python implementations. I started working on the project due to my > frustrations stemming from getting MySQLdb working on Snow Leopard. > PyMySQL has been tested on CPython 2.3+, Jython, IronPython and PyPy, > and we have an unreleased Python 3.0 branch in Subversion. I encourage > anyone hoping to connect to MySQL from Python to check it out and > report any bugs you might find! Our current focus has been bringing it > up to compatibility with SQLAlchemy and Django, and we have by and > large achieved that goal with a high level of performance. > > This is of specific interest to Django users, as one can simply > replace references to "MySQLdb" with "pymysql" and run their Django > apps on platforms that are difficult to get working with MySQLdb (like > Mac OSX Snow Leopard). > > Check it out athttp://www.pymysql.org/. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Spam filters for Django?
I'm working on a Django-based site that consists mostly of user- generated content: reviews, comments, tweet_like posts, etc. I'm concerned about spam. Are there any spam filters available for Django? If not, what types of algorithm can be used for spam filtering? On a more general note, does anyone know how do major sites like Amazon and Yelp prevent spams in their user-submitted reviews? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Spam filters for Django?
Only logged in users will be allowed to post. But that wouldn't stop spammers from logging in and posting spam. An example is Apple's new social network, Ping. Only logged in users are allowed to post comments there. But it's still flooded with spam immediately after its launch: http://www.readwriteweb.com/archives/apples_ping_overrun_with_spam.php "The fraudsters have created iTunes profiles and are posting links to a number of online scams, including ones that promises "free iPhones" or "free iPads" in exchange for filling out online surveys. For the most part, these suspicious links are being posted in the comments sections "Apple doesn't require a credit card or any other positive identification in order to establish an account on Ping "Given those lax sign-up requirements, however, it's somewhat surprising that Apple didn't build in a good spam filtration system into its social network, too. The types of links being posted now are what any halfway decent blog commenting system like Disqus or Echo would pick up automatically, or at least flag for review." So 'm looking for some sort of automatic spam filtering or flagging in addition to the logged-in requrement. On Sep 4, 1:10 am, Kenneth Gonsalves wrote: > On Fri, 2010-09-03 at 21:56 -0700, Andy wrote: > > I'm working on a Django-based site that consists mostly of user- > > generated content: reviews, comments, tweet_like posts, etc. > > > I'm concerned about spam. Are there any spam filters available for > > Django? If not, what types of algorithm can be used for spam > > filtering? > > the three most common ways are to only allow logged in users to post, > captchas or akismet or a combination of the three. > -- > regards > Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Composite Primary Key Support
What are the downsides of just importing & using SQLAlchemy (which supports composite PK) in a Django program? On Sep 3, 10:43 pm, Russell Keith-Magee wrote: > On Sat, Sep 4, 2010 at 7:17 AM, Brendon wrote: > > I have a project where we have an existing database which uses > > composite (multiple) primary keys for some of the tables. I want to > > move everything over from PHP into DJango without changing the DB. > > Reading the DJango docs though, it seems composite primary keys are > > not supported. I looked online and found that someone was working on > > this, but just noticed then that the ticket was closed and marked as > > "wontfix". > > >http://code.djangoproject.com/ticket/373 > > You must be looking at a different page to me, because this ticket is > open and marked "accepted and assigned" when i look at it. > > > Can anyone tell me for sure if this support has been abandoned or at > > least any information on the status of this? > > > I wasn't sure if this was the best place to ask or django-developers. > > Please let me know i should move this question over. > > Mutli-column composite keys are not currently supported by Django. > Adding support for multi-column keys (primary or otherwise) is > something that has been long discussed, and there is agreement that it > is a desirable feature -- which is why the ticket is marked accepted. > > What is missing is someone to actually do the work. It's easy to get a > basic implementation working, but there are a lot of nasty edge cases > in admin and general usage that need to be resolved. Nothing is going > to get committed to trunk until these issues have been sorted out. > > To the best of my knowledge, nobody is actively working on this at the > moment. If you're interested in contributing, django-developers is the > place to put forward your ideas and plans. > > Yours > Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ANN: PyMySQL 0.3
Thanks Pete. I'm definitely interested in using PyMySQL for production. I'm interested in running Django in an async mode using gevent (http:// www.gevent.org/). gevent provides a money patch that turns any Python code into non-blocking. The problem is that MySQLdb is written in C, so it'd still block, which would kinda defeat the whole purpose of having an async Django app if every database access is blocking. PyMySQL looks like could be a great solution for this problem. In fact there's already a thread in the gevent mailing list talking about PyMySQL. You might want to drop by: http://groups.google.com/group/gevent/browse_thread/thread/b5f7bf44b7690ed9 On Sep 4, 4:58 pm, Pete Hunt wrote: > Hi Andy - > > Below is a patch that will let Django use pymysql if MySQLdb is not > available. Currently it is not in use in production anywhere but I am > hoping to change that soon. Currently its primary use is prototyping > applications that are being developed on Mac OSX but deployed on > Linux. If you are interested in using it in production please let me > know and I will be sure to prioritize any tickets related to > production issues. > > Simply search-replacing MySQLdb with pymysql in django/db/backends/ > mysql/base.py and django/db/backends/mysql/introspection.py will get > it to work. I will submit a patch soon that tries to import MySQLdb > but falls back to pymysql if it is not available. > > Pete > > On Sep 3, 5:20 pm, Andy wrote: > > > > > Pete, > > > Would you recommend PyMySQL for production use? > > > Which parts of Django do I need to modify in order to use it with > > PyMySQL instead of MySQLdb? > > > Thanks. > > > On Sep 3, 2:07 pm, Pete Hunt wrote:> I’m proud to > > announce the release of PyMySQL 0.3. For those of you > > > unfamiliar with PyMySQL, it is a pure-Python drop-in replacement for > > > MySQLdb with an emphasis on compatibility with MySQLdb and for various > > > Python implementations. I started working on the project due to my > > > frustrations stemming from getting MySQLdb working on Snow Leopard. > > > PyMySQL has been tested on CPython 2.3+, Jython, IronPython and PyPy, > > > and we have an unreleased Python 3.0 branch in Subversion. I encourage > > > anyone hoping to connect to MySQL from Python to check it out and > > > report any bugs you might find! Our current focus has been bringing it > > > up to compatibility with SQLAlchemy and Django, and we have by and > > > large achieved that goal with a high level of performance. > > > > This is of specific interest to Django users, as one can simply > > > replace references to "MySQLdb" with "pymysql" and run their Django > > > apps on platforms that are difficult to get working with MySQLdb (like > > > Mac OSX Snow Leopard). > > > > Check it out athttp://www.pymysql.org/. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ANN: PyMySQL 0.3
On Sep 5, 5:29 am, Daniel Roseman wrote: > If I get some time I'll try and work up an example. Please do Daniel. That'd really help. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django with PyPy JIT?
Anyone tried running Django with PyPy JIT? What are the steps to set it up? Is it stable? PyPy benchmark shows almost 3X speed up of Django and they also said it would reduce memory consumption. I'm interested in trying it out. Just want to learn about anyone's experience with running Django on PyPy. Are there any pitfalls? Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How do you avoid this race condition in Django?
I have a model MyModel that has a field expiration_datetime. Every time a user retrieves an instance of MyModel I need to first check if it has expired or not. If it has expired, than I need to increment some counter, update others, and then reset the expiration_datetime to some time in the future. So the view would do something like: if object.expiration_datetime < datetime.datetime.now(): object.counter = F('counter') + 1 object.expiration_datetime = F('expiration_datetime') + datetime.timedelta(days=1) object.save() There's a race condition in the code above. Say thread 1 checks and finds that the current instance has expired, it proceeds to increment the counter and reset the expiration datetime. But before it could do so, thread 2 is scheduled and does the same. By the time thread 1 finally finishes, counter has been incremented twice and expration_datetime has been reset twice. This looks like a pretty common issue. How do I handle it? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How do you avoid this race condition in Django?
How do I freeze a row in database? On Sep 6, 11:05 am, Jim wrote: > Maybe I'm not understanding the question but I'd freeze the row in the > database, do the work, and then unfreeze the row. > > Jim -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django with PyPy JIT?
Thanks Alex, Is there any instructions on how to set up django with PyPy you could point me to? Andy On Sep 5, 7:50 pm, Alex_Gaynor wrote: > On Sep 5, 4:40 pm, Andy wrote: > > > Anyone tried running Django with PyPy JIT? > > > What are the steps to set it up? Is it stable? > > > PyPy benchmark shows almost 3X speed up of Django and they also said > > it would reduce memory consumption. I'm interested in trying it out. > > Just want to learn about anyone's experience with running Django on > > PyPy. > > > Are there any pitfalls? > > > Thanks. > > Hi Andy, > > I haven't deployed Django under PyPy ever, however I have been working > to ensure they work together. If you take a look at the videos from > here:http://morepypy.blogspot.com/2010/08/europython-2010-videos-available... > you can see some of the stuff that's been done with it. The one major > pitfall is that there are no c-extensions, so you can't use something > like psycopg2. > > Alex -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ANN: PyMySQL 0.3
On Sep 10, 11:18 am, Andy Dustman wrote: > Uh, no. > > MySQLdb releases the GIL on any blocking call, so other threads can run. > > Django is *not* asynchronous. It's threaded. The default Django behavior is threaded. But it can be made to run in async mode, where socket communication doesn't block. That way one Django thread can serve multiple users concurrently. Check out gevent for details. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Possible to have dynamic drop down list in ModelForm?
I have a model FieldReport that has, among other fields, these two fields: -country -city Both "country" and "city" are lists of choices. I want to have a form FieldReportForm as a ModelfForm based on the model FieldReport. I want to have "country" and "city" represented as drop down lists. Moreover, "city" should be a dynamic list based on the selected value of "country". For example, if someone selects the value "US" for "country", then "city" should be a list of US cities only, all cities in other countries shouldn't be loaded onto that list. Is this something that would work with Django's ModelForm? How would you implement something like this? Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ANN: PyMySQL 0.3
Great! Thank you very much. On Sep 29, 6:56 pm, Bo Shi wrote: > The following patch to your application's manage.py will allow you to > use pymysql without patching Django. > > #!/usr/bin/env python > +try: > + import pymysql > + pymysql.install_as_MySQLdb() > +except ImportError: > + pass > + > > On Sep 10, 12:25 pm, Andy wrote: > > > On Sep 10, 11:18 am, Andy Dustman wrote: > > > > Uh, no. > > > > MySQLdb releases the GIL on any blocking call, so other threads can run. > > > > Django is *not* asynchronous. It's threaded. > > > The default Django behavior is threaded. > > > But it can be made to run in async mode, where socket communication > > doesn't block. That way one Django thread can serve multiple users > > concurrently. > > > Check out gevent for details. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django for internationalized sites - are models.User internationalized?
According to documentation (http://docs.djangoproject.com/en/dev/ topics/auth/), models.User contains: first_name Optional. 30 characters or fewer. last_name Optional. 30 characters or fewer. email Optional. E-mail address. Are "first_name" & "last_name" limited to alphanumeric characters or can they contain non-English characters like "ü" or non-European characters like "黒"? What characters are allowed in the "email" field? Again can it contain non-English or non-European characters? Anyone who have built non-English or non-European websites using Django? What is your experience? Any pitfalls I need to be aware of? Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django for internationalized sites - are models.User internationalized?
On Oct 2, 1:45 am, Torsten Bronger wrote: Thanks for responding. > Hallöchen! > > > Are "first_name" & "last_name" limited to alphanumeric characters > > or can they contain non-English characters like "ü" or > > non-European characters like "黒"? > > Yes. "Yes" is in "first_name" & "last_name" can contain non-English characters like "ü" or non-European characters like "黒"? > > > What characters are allowed in the "email" field? Again can it > > contain non-English or non-European characters? > > I don't know, but I hope not! You mean you hope the field "email" is not allowed to contain non- English or non-European characters? But real email addresses do contain those characters: http://en.wikipedia.org/wiki/Email_address#Internationalization Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django for internationalized sites - are models.User internationalized?
On Oct 2, 3:27 am, Torsten Bronger wrote: > Hallöchen! > > Andy writes: > > On Oct 2, 1:45 am, Torsten Bronger > > wrote: > > > Thanks for responding. > > >>> Are "first_name" & "last_name" limited to alphanumeric > >>> characters or can they contain non-English characters like "ü" > >>> or non-European characters like "黒"? > > >> Yes. > > > "Yes" is in "first_name" & "last_name" can contain non-English > > characters like "ü" or non-European characters like "黒"? > > The latter. > > > [...] > > > You mean you hope the field "email" is not allowed to contain non- > > English or non-European characters? > > > But real email addresses do contain those characters: > >http://en.wikipedia.org/wiki/Email_address#Internationalization > > I read "informal" and "experimental" there. Maybe, but I know people with real email addresses like that. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Any way to select which Model to initialize without resorting to "if-elfi" statements?
I need to model many different product categories such as TV, laptops, women's apparel, men's shoes, etc. Since different product categories have different product attributes, each category has its own separate Model: TV, Laptop, WomensApparel, MensShoes, etc. And for each Model I created a ModelForm. Hence I have TVForm, LaptopForm, WomensApparelForm, MensShoesForm, etc. Users can enter product details by selecting a product category through multi-level drop-down boxes. Once a user has selected a product category, I need to display the corresponding product form. The obvious way to do this is to use a giant `if-elif` structure: # category is the product category selected by the user if category == "TV": form = TVForm() elif category == "Laptop": form = LaptopForm() elif category == "WomensApparel": form = WomensApparelForm() ... Unfortunately there could be hundreds if not more of categories. So the above method is going to be error-prone and tedious. Is there any way I could use the value of the variable `category` to directly select and initialize the appropriate `ModelForm` without resorting to a giant `if-elif` statement? Something like: # This doesn't work model_form_name = category + "Form" form = model_form_name() Is there any way to do this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to use django session outside of the view
>>> from django.contrib.sessions.backends.db import SessionStore >>> s = SessionStore(session_key='2b1189a188b44ad18c35e113ac6ceead') >>> s['last_login'] = datetime.datetime(2005, 8, 20, 13, 35, 10) >>> s['last_login'] datetime.datetime(2005, 8, 20, 13, 35, 0) >>> s.save() The above shows how to use django outside of the view but I still am not full clear on the 32-character session_key. Assuming that I generate the key do I need to worry about using duplicated values for the session_key and if so what is the best way to avoid duplications in django? Kimani -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Questions about Django's authentication system
A few questions about Django's authentication system: - Once a user is logged in, how long does he remain logged in? Is there any way to configure this - e.g. "users will remain logged in for 24 hours"? - Once a user provided a matching username & password and is authenticated, then what? In subsequent page views how does Django know that this user is logged in? I'm guessing Django creates a cookie and stores the cookie in SESSION_ENGINE, every time a user request a page, Django gets that user's cookie from browser and uses it to query SESSION_ENGINE. Is that correct? - Does it mean that Django must hit SESSION_ENGINE for every single page view? Thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
html in django password_reset_email.html
I recently tried to send the following in a test password email from a site I am creating: This is a test reset password email. However when I received the email it displayed the "This is a test reset password email.". My question is how can I send a styled email using html tags and possibly even css when using the password_reset_email.html template that goes with django's view.password_reset? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Mod_Python and everything loaded, Apache serving HTML files without using Django first
This isn't directly related to your question, but mod_python is not a recommended method of deploying Django. Support for it will be deprecated. You might want to check out mod_wsgi. On Nov 1, 5:15 pm, The End wrote: > I've finally got mod_python and mysqldb working with apache (long > story short, can't install wsgi for various reasons and i'm using > python 2.4.3... for various reasons...). > > However > > Now when i load up the home page (just typing 'localhost' into > firefox) i get the literal HTML representation of index.html, without > the dynamics filling in. I can only assume that apache is not using > Django to return these requests. > > I only have 1 Virtual Host and Location tag in my entire Apache > Configuration File (with all the standard stuff, i didn't turn > anything off): > > LoadModule python_module /usr/lib64/httpd/modules/mod_python.so > > > ServerName Sweetman > ServerAdmin sweet...@sweetman.com > DocumentRoot /srv/www/sweetman/ > > > SetHandler python-program > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE sweetman.settings > PythonDebug On > PythonPath "[ '/sweetman_live/sweetman' , '/usr/lib/ > python2.4/site-packages/django/' , '/srv/www/'] + sys.path" > > > > SetHandler none > > > ErrorLog /srv/www/sweetman/logs/error.log > CustomLog /srv/www/sweetman/logs/access.log combined > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: html in django password_reset_email.html
On Nov 2, 4:50 am, Tom Evans wrote: > On Tue, Nov 2, 2010 at 9:07 AM, andy wrote: > > I recently tried to send the following in a test password email from a > > site I am creating: > > > This is a test reset password email. > > > However when I received the email it displayed the "This is a test > > reset password email.". > > > My question is how can I send a styled email using html tags and > > possibly even css when using the password_reset_email.html template > > that goes with django's view.password_reset? > > I don't know about the specifics of your particular issues, but to > send HTML emails: > > Create an instance of django.core.mail.EmailMultiAlternatives, passing > in your subject, text version of the email, from address, list of > recipients. Render your HTML version of the email, and attach it to > the email, and then send it. > > eg: > > from django.core.mail import EmailMultiAlternatives > msg = EmailMultiAlternatives('Subject', 'This is the text version', > 'f...@address.com', [ 'recipie...@address.com',]) > html_version = ... > msg.attach_alternative(html_version, 'text/html') > msg.send() > > There are lots of 'gotchas' when sending HTML email. Don't expect > externally referenced resources to be available, don't expect styles > to work correctly in all UAs, don't expect any JS to work. > > Cheers > > Tom Thanks for the reply, Django password_reset view used send_mail() which seem to send only text. apparently you have to use EmailMultiAlternatives as you pointed out to send html content guess I will have to create my own view and use this instead if I want to send html. Then again it is probably a good idea to send password reset information in plant text. Since it pretty any email client would be able to read plain text. Thanks again Kimani -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: html in django password_reset_email.html
On Nov 2, 4:50 am, Tom Evans wrote: > On Tue, Nov 2, 2010 at 9:07 AM, andy wrote: > > I recently tried to send the following in a test password email from a > > site I am creating: > > > This is a test reset password email. > > > However when I received the email it displayed the "This is a test > > reset password email.". > > > My question is how can I send a styled email using html tags and > > possibly even css when using the password_reset_email.html template > > that goes with django's view.password_reset? > > I don't know about the specifics of your particular issues, but to > send HTML emails: > > Create an instance of django.core.mail.EmailMultiAlternatives, passing > in your subject, text version of the email, from address, list of > recipients. Render your HTML version of the email, and attach it to > the email, and then send it. > > eg: > > from django.core.mail import EmailMultiAlternatives > msg = EmailMultiAlternatives('Subject', 'This is the text version', > 'f...@address.com', [ 'recipie...@address.com',]) > html_version = ... > msg.attach_alternative(html_version, 'text/html') > msg.send() > > There are lots of 'gotchas' when sending HTML email. Don't expect > externally referenced resources to be available, don't expect styles > to work correctly in all UAs, don't expect any JS to work. > > Cheers > > Tom Thanks for the reply, Django password_reset view used send_mail() which seem to send only text. apparently you have to use EmailMultiAlternatives as you pointed out to send html content guess I will have to create my own view and use this instead if I want to send html. Then again it is probably a good idea to send password reset information in plant text. Since it pretty any email client would be able to read plain text. Thanks again Kimani -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: html in django password_reset_email.html
On Nov 2, 4:50 am, Tom Evans wrote: > On Tue, Nov 2, 2010 at 9:07 AM, andy wrote: > > I recently tried to send the following in a test password email from a > > site I am creating: > > > This is a test reset password email. > > > However when I received the email it displayed the "This is a test > > reset password email.". > > > My question is how can I send a styled email using html tags and > > possibly even css when using the password_reset_email.html template > > that goes with django's view.password_reset? > > I don't know about the specifics of your particular issues, but to > send HTML emails: > > Create an instance of django.core.mail.EmailMultiAlternatives, passing > in your subject, text version of the email, from address, list of > recipients. Render your HTML version of the email, and attach it to > the email, and then send it. > > eg: > > from django.core.mail import EmailMultiAlternatives > msg = EmailMultiAlternatives('Subject', 'This is the text version', > 'f...@address.com', [ 'recipie...@address.com',]) > html_version = ... > msg.attach_alternative(html_version, 'text/html') > msg.send() > > There are lots of 'gotchas' when sending HTML email. Don't expect > externally referenced resources to be available, don't expect styles > to work correctly in all UAs, don't expect any JS to work. > > Cheers > > Tom Thanks for the reply, Django password_reset view used send_mail() which seem to send only text. apparently you have to use EmailMultiAlternatives as you pointed out to send html content guess I will have to create my own view and use this instead if I want to send html. Then again it is probably a good idea to send password reset information in plant text. Since it pretty any email client would be able to read plain text. Thanks again Kimani -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: html in django password_reset_email.html
On Nov 2, 4:50 am, Tom Evans wrote: > On Tue, Nov 2, 2010 at 9:07 AM, andy wrote: > > I recently tried to send the following in a test password email from a > > site I am creating: > > > This is a test reset password email. > > > However when I received the email it displayed the "This is a test > > reset password email.". > > > My question is how can I send a styled email using html tags and > > possibly even css when using the password_reset_email.html template > > that goes with django's view.password_reset? > > I don't know about the specifics of your particular issues, but to > send HTML emails: > > Create an instance of django.core.mail.EmailMultiAlternatives, passing > in your subject, text version of the email, from address, list of > recipients. Render your HTML version of the email, and attach it to > the email, and then send it. > > eg: > > from django.core.mail import EmailMultiAlternatives > msg = EmailMultiAlternatives('Subject', 'This is the text version', > 'f...@address.com', [ 'recipie...@address.com',]) > html_version = ... > msg.attach_alternative(html_version, 'text/html') > msg.send() > > There are lots of 'gotchas' when sending HTML email. Don't expect > externally referenced resources to be available, don't expect styles > to work correctly in all UAs, don't expect any JS to work. > > Cheers > > Tom Thanks for the reply, Django password_reset view used send_mail() which seem to send only text. apparently you have to use EmailMultiAlternatives as you pointed out to send html content guess I will have to create my own view and use this instead if I want to send html. Then again it is probably a good idea to send password reset information in plant text. Since it pretty any email client would be able to read plain text. Thanks again Kimani -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django apps and models
Hi guys, Say I have a CUSTOMER, BRANCH and a SALES table for my project design. Question, should is it wise to create a customer, branch and sales app. I like this idea of doing this but I have a few issues. 1. If I create a customer app and create a Customer model class that has a ForeignKey relationship with the branch table, I would seem that I have to create the branch application first and create its Branch model class. 2. Also what if I plan for some reason to populate the branch table using the admin interface, to avoid creating a view and templates for it. Would I still make sense to create app just to host possibly one model. What came to mind what to create a app that only manages all the database table or at least just table like branch which I don't plant to create views for. I guess this is what generally happens in the MVC frame works that are now app oriented like django. I like the django Idea of having models in the apps at it seems more portable, so I would like to keep things this way as much as possible which is why I as seeking some advise on how to possibly deal with this kind of situation. Maybe my opinion of an app is flawed is some way, which is why I am having this issue. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django apps and models
Thanks for the advise, I had considers this option, and I really dose seem that apps are move for generic features as you pointed out but I have about 10 tables which are as depended in structure as the ones noted above. I really don't what to have too much code in one view.py or model.py file. For now I plan to create a customer app without the ForeignKey relationship, work on it and when I add the branch model I add the relationship that links them. Probably a bad idea but thats the bes I have so far, this is something I'll need to think about a bit more though. Thanks for your 2c Kimani On Nov 5, 8:37 am, derek wrote: > I'll add my 2c here... > > I don't think you need to create an app for this (not yet). Just > create a normal Django project and go from there. Apps are more meant > for very generic types of functionality that can be used in many, many > situations e.g. tagging. > > Your design is still very broad and so hard to comment on. You may > want to consider a many-to-many between customer and branch. Then you > can add data for each without being dependant on either existing > first. This also gives you the flexibility to link up the same > customer to many branches. > > On Nov 4, 6:24 pm, andy wrote: > > > Hi guys, > > > Say I have a CUSTOMER, BRANCH and a SALES table for my project design. > > > Question, should is it wise to create a customer, branch and sales > > app. I like this idea of doing this but I have a few issues. > > > 1. If I create a customer app and create a Customer model class that > > has a ForeignKey relationship with the branch table, I would seem that > > I have to create the branch application first and create its Branch > > model class. > > > 2. Also what if I plan for some reason to populate the branch table > > using the admin interface, to avoid creating a view and templates for > > it. Would I still make sense to create app just to host possibly one > > model. > > > What came to mind what to create a app that only manages all the > > database table or at least just table like branch which I don't plant > > to create views for. I guess this is what generally happens in the MVC > > frame works that are now app oriented like django. > > > I like the django Idea of having models in the apps at it seems more > > portable, so I would like to keep things this way as much as possible > > which is why I as seeking some advise on how to possibly deal with > > this kind of situation. Maybe my opinion of an app is flawed is some > > way, which is why I am having this issue. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Can extra() be used to implement JOIN?
I have a Q&A type of site with the following models: class Question(models.Model): title = models.CharField(max_length=70) details = models.TextField() class Answer(models.Model): question_id = IntegerField() details = models.TextField() I need to display a specific question together with its answers. Normally I'd need 2 queries to do that: Question.objects.get(id=1) Answer.objects.get(question_id=1)[:10] I'm hoping to retrieve everything using one query. In MySQL it'd be: SELECT * FROM Question JOIN Answer ON Question.id=Answer.question_id WHERE Question.id=1 LIMIT 10 Is there anyway I could do this through Django's ORM? Would extra() help in this case? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Saving images in django
Django recommends saving images to the file system since this gives better performance than storing the files in a database. However I don't seen any documentation on how to restrict access to those files by user. If someone knows the url to your image directory they could possibly view all the content of that directory. If you create a social network or a multi tenant application how will you handle this issue? While writing this up I learned about preventing directory listing, is this secure enough. how about obfuscating file or directory names. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Saving images in django
Thanks for the info very useful. On Nov 10, 6:34 pm, Łukasz Rekucki wrote: > On 11 November 2010 03:19, andy wrote: > > > Django recommends saving images to the file system since this gives > > better performance than storing the files in a database. However I > > don't seen any documentation on how to restrict access to those files > > by user. If someone knows the url to your image directory they could > > possibly view all the content of that directory. If you create a > > social network or a multi tenant application how will you handle this > > issue? > > > While writing this up I learned about preventing directory listing, is > > this secure enough. how about obfuscating file or directory names. > > This largely depends on what your HTTP server can do, but with Apache > you can use the X-Sendfile header. This works like this: > > 0. Install mod_xsendfile and put "XSendFile On" in your Apache config. > See also [1]. > > 1. Instead of putting the images in a location with all the other > media, put it in a protected location - one which the server can read, > but not associated with any Location. > > 2. Create a view that will check permissions for a given file. As a > response return an empty HttpResponse with "X-Sendfile" header > containing the full filesystem path of the file to be server, or a 403 > if the person is not permitted. > > 3. Apache will look at the response for X-Sendfile header and if > present the file that the header points to will be server as a > response instead. > > This way you can check permission in your Django app, while still > having the speed of serving static files directly by HTTP server. A > similar solution is also availble for nginx[2] and probably other > webservers. > > [1]:https://tn123.org/mod_xsendfile/ > [2]:http://wiki.nginx.org/NginxXSendfile > > -- > Łukasz Rekucki -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: remember me in login
you might also want to take a look at this "Remember me for login" snippet from django snippets http://djangosnippets.org/snippets/1881/ On Nov 27, 6:00 am, robos85 wrote: > request.session.set_expiry() it's ideal for me:) > > On 27 Lis, 02:01, Addy Yeow wrote: > > > i use thishttp://djangosnippets.org/snippets/1881/ > > > On Sat, Nov 27, 2010 at 8:07 AM, robos85 wrote: > > > Is there any easy way to do remember me trigger during login? > > > I know that there is SESSION_COOKIE_AGE but it's set site-wide. Is > > > there any possibility to set expiration at browser close or x time? > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Django users" group. > > > To post to this group, send email to django-us...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com > > groups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Comments by guest and foreign key in model
Well you don't have to make the foreign key field required, that way comments belonging to guest users can have a blank foreign key Possibly you could also create a default guest user that is assign to comments made by guest users. I generally having my application depending on the creation of some default record so I would probably go for the first option. On Dec 5, 3:14 pm, robos85 wrote: > Hi, > I need to create comments system. Either guests and logged users can > comment. How can I do that? > I want to make a Foreign Key to User model but then, how to add gust's > comemnts? I could make it in 2 separate tables, but it would be nice > to have it in 1 table. > > Any ideas? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Is their much benefit In using a second hidden salt
So I was having a bit of confusion over the method that django uses to protect passwords. The issues I had was that It seen unsecured to have the salt publicly available in the database since anyone who gets hold of the database would know the salt. After rereading the django book and doing some additional research I discovered that this method was particularly targeted at rainbow tables attacks and is indeed view by many as a better option than a system wide hidden salt. However I'm a bit curious about the significance of adding a second salt to the password before it is hashed and then using the regular per-user salt. Currently my opinion is that their is added benefit since it make dictionary attacks more challenging and possibly almost impossibly if the attacker does not know the hidden salt. Django has a secretKey in the setting file I wondering why this could not have been used as second salt in the authentication system. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Error when running python manage.py loaddata datadump.json
Generally when I get an error similar to that(not necessarily when using django) It means that I have violated some field that has a unique constraint. Look in you database and see if you have a constrain on that table. On Dec 6, 2:55 pm, jc wrote: > I'm migrating my Django database from sqlite to mysql. I've done the > following with no problems: > python manage.py dumpdata > datadump.json Changed my settings.py to > the mysql database. > > But when I issue the following command python manage.py loaddata > datadump.json I get this error: > IntegrityError: (1062, "Duplicate entry '13-13' for key > 'from_category_id'") > > How do I go go about fixing this issue so that I can run the command > again and hopefully load my data into my site? > > thanks, > j. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Generic ForeignKey in Database Queries
>From the django doc "Due to the way GenericForeignKey is implemented, you cannot use such fields directly with filters (filter() and exclude(), for example) via the database API. They aren't normal field objects." http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#generic-relations On Dec 6, 6:24 pm, Katrina wrote: > I have a model set up thusly: > > from django.contrib.contenttypes.models import ContentType > from django.contrib.contenttypes import generic > > Item(models.Model): > content_type = models.ForeignKey(ContentType) > object_id = models.PositiveIntegerField() > object = generic.GenericForeignKey() > > If I try to perform queries in the format > Item.objects.filter(object=some-object), I raise a FieldError: "Cannot > resolve keyword 'object' into field". But if I have some instance of > Item and I call item-instance.object, it returns the object correctly. > > Is this a behavioral malfunction, or are Generic ForeignKeys not meant > to be used in database queries? If they are not, is there any real > advantage to having one? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: General question about NOT EXISTS...
Well django has a ISNULL which I guess could be use to get the result that you want. I'm a bit new to django and have not done any many-to- many relationships as yeah but I'm guessing you could do something like this: Lest say table A = Blog, B = entry and C = blogentry Blog.objects.filter(entry__isnull=True) If I am correct this should return a list of blogs that does not have any entires. On Dec 7, 12:06 am, Wes Wagner wrote: > This is a generic question because I am a newbie and things are not > gelling quite 100% on how to write Q statements to get a filter to do > everything one wants. > > Let's say you have Table A and Table B and Table C, where Table B has > a foreign key to table A and Table C (a manually constructed many to > many because it has extra data elements) > > Now I want to build a list of all elements from table A, where not > exists a record in Table B that is related to table A and also has a > couple values = to something, and related to a particular table C > record) > > In SQL this would look like: > > select * from a where not exists (select * from B,C where > a.id=b.aforeignkey and c.id=b.cforeignkey and b.filter1=blah and > c.filter2=blah) > > How does that look when you are building an object list in the Q( )... > style format? Where I am hung up is finding syntax examples of how to > do the functional equivalent of a sql where not exists clause. > > Is there a way to do this without using .extra() and using just normal > django? > > -Wes Wagner -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: General question about NOT EXISTS...
Well django has a ISNULL which I guess could be use to get the result that you want. I'm a bit new to django and have not done any many-to- many relationships as yeah but I'm guessing you could do something like this: Lest say table A = Blog, B = entry and C = blogentry Blog.objects.filter(entry__isnull=True) If I am correct this should return a list of blogs that does not have any entires. On Dec 7, 12:06 am, Wes Wagner wrote: > This is a generic question because I am a newbie and things are not > gelling quite 100% on how to write Q statements to get a filter to do > everything one wants. > > Let's say you have Table A and Table B and Table C, where Table B has > a foreign key to table A and Table C (a manually constructed many to > many because it has extra data elements) > > Now I want to build a list of all elements from table A, where not > exists a record in Table B that is related to table A and also has a > couple values = to something, and related to a particular table C > record) > > In SQL this would look like: > > select * from a where not exists (select * from B,C where > a.id=b.aforeignkey and c.id=b.cforeignkey and b.filter1=blah and > c.filter2=blah) > > How does that look when you are building an object list in the Q( )... > style format? Where I am hung up is finding syntax examples of how to > do the functional equivalent of a sql where not exists clause. > > Is there a way to do this without using .extra() and using just normal > django? > > -Wes Wagner -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: General question about NOT EXISTS...
Sorry for the double post. The table should have been A = Blog, B = blogentry and C = entry On Dec 7, 1:12 am, andy wrote: > Well django has a ISNULL which I guess could be use to get the result > that you want. I'm a bit new to django and have not done any many-to- > many relationships as yeah but I'm guessing you could do something > like this: > > Lest say table A = Blog, B = entry and C = blogentry > > Blog.objects.filter(entry__isnull=True) If I am correct this should > return a list of blogs that does not have any entires. > > On Dec 7, 12:06 am, Wes Wagner wrote: > > > This is a generic question because I am a newbie and things are not > > gelling quite 100% on how to write Q statements to get a filter to do > > everything one wants. > > > Let's say you have Table A and Table B and Table C, where Table B has > > a foreign key to table A and Table C (a manually constructed many to > > many because it has extra data elements) > > > Now I want to build a list of all elements from table A, where not > > exists a record in Table B that is related to table A and also has a > > couple values = to something, and related to a particular table C > > record) > > > In SQL this would look like: > > > select * from a where not exists (select * from B,C where > > a.id=b.aforeignkey and c.id=b.cforeignkey and b.filter1=blah and > > c.filter2=blah) > > > How does that look when you are building an object list in the Q( )... > > style format? Where I am hung up is finding syntax examples of how to > > do the functional equivalent of a sql where not exists clause. > > > Is there a way to do this without using .extra() and using just normal > > django? > > > -Wes Wagner -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: redirect after login
Did you get the next parameter in the login template and append it to form action, If that is not done then once the form is submitted the next param would be lost. On Dec 7, 5:45 am, vamsy krishna wrote: > request.GET returns an empty dict > > On Dec 7, 3:35 pm, Kenneth Gonsalves wrote: > > > On Tue, 2010-12-07 at 02:31 -0800, vamsy krishna wrote: > > > redirect_to = request.REQUEST.get('next') > > > how about > > redirect_to = request.GET? > > -- > > regards > > Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Looking for Django developer in DC
Hey, I own and run a small professional services company in the greater DC area (aajinteractive.com). We do project based software development work, staff augmentation and direct recruiting for our clients. I have a client who wants to hire a solid Django developer. The rite person will have: 1) Solid development skills 2) Good familiarity developing on the LAMP stack 3) Experience with Python and Django 4) At least 2 years true professional experience 5) A BS/BA degree in CS or related field 6) Already resides in the greater DC area 7) A great attitude, high energy, solid communication skills 8) A desire to work for a very cool company (my client's), writing code for a huge consumer facing website If this sounds like you, please send your resume to me asap, and we'll see what we can make happen. Thanks, Andy www.aajinteractive.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
'Context' object has no attribute 'period'
I am (still) new to Django and a novice at relational databases, so I am having some problems. I've read and read, but can't sort this out. I have a customer enter data into a form. The model is here: class Order_Info(models.Model): date_stamp = models.DateTimeField(auto_now_add=True) year = models.IntegerField() period = models.IntegerField(editable=False, blank=True, null=True) direction = models.CharField(max_length=20, choices=direction_choices) email = models.EmailField("Email Address") I save the session data in this view: def order(request): if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): current_order = form.save() order_info = Context({'order_info': current_order}) request.session['order_info'] = order_info return HttpResponseRedirect('/pdf_test/') Then redirect them to the page called pdf_test where I want to use the session data to lookup and display data from the model named Chart: class Chart(models.Model): ch_period = models.IntegerField() ch_direction = models.CharField(max_length=20) general = models.CharField(max_length=200) top_left = models.CharField(max_length=20) top_center = models.CharField(max_length=20) top_right = models.CharField(max_length=20) mid_left = models.CharField(max_length=20) mid_center = models.CharField(max_length=20) mid_right = models.CharField(max_length=20) low_left = models.CharField(max_length=20) low_center = models.CharField(max_length=20) low_right = models.CharField(max_length=20) My view for pdf_test is where I encounter problems: def pdf_test(request): order_info = request.session['order_info'] p = order_info.period c = Context({'chart': Chart.objects.filter(ch_period = p)}) return render_to_response('pdf_test.html', order_info, c) No matter what I try, I can't seem to extract period from that order_info data. Can anybody tell me what I'm doing wrong? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
(Funny Video Clip) Amazing singer with dolphin tone!
Wow!How high can he go?? He scares me. So beautiful dolphin tone . http://www.gamestar.ws/en-video/Vitas.htm Please tell us about your opinion. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Settings.py variables in CSS file
We are hosting our media files on a separate server from our web server. We are also using SVN for all of the django files, and the parent directories for the remote media files will correlate to the SVN version (i.e. see "media_231" below). The goal here is to be able to embed django settings.py global variables into the CSS file, so that we can control the media url from settings, and have it dynamically fill the CSS file. The ideal solution is to have the following line in settings.py: MEDIA_HOST = 'http://www.mediaserver.com/media_231' Then in the CSS file have this: background: #333 url({{ MEDIA_HOST }}/images/diag.gif This obviously doesn't work for a number of reasons, so I made a work around. I made a template tag (css_path) that reads in the remote CSS file, replaces custom variables in the CSS with their values from settings.py, and writes/returns a new .css file. {% load process_css %} {% get_css_file %} It works, except it seems horribly inefficient. The problem is *each time* a page is requested, it would have to do a remote URL Request, write the new css file, etc. Has anyone been confronted with this problem. Is there an easier solution? Thanks in advance, Andy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Settings.py variables in CSS file
Thanks for the responses. > Why not use relative paths in yourcssfiles? They're relative to thecssfile, > not the html file, so you can do url(../images/diag.gif). > I'm assuming that all media files are on the same host and that only > the base media directory name is adapted to the svn version though. Simon, excellent idea. I guess I was going for something way too complicated, where your solution should've been completely obvious. However, if you want other variables (other than just the media host), then Jame's idea sounds pretty legit. Thanks again, Andy --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
upload_to dir in ImageField
I'm having some trouble with the object.get__url() results for my image field. I'm trying to get this going with the Django's (ver 0.95) development server in WinXP. I have the following line in my model: avatar = models.ImageField(upload_to='users/', blank=True, null=True) I have the following in my settings.py: MEDIA_URL = '/media/images/' When I call object.get_avatar_url in either a view or a template it returns the following URL: /media/images/image.jpg It's missing the 'upload_to' directory, it should be this: /media/images/users/image.jpg According to the FileField documentation it is supposed to append the upload_to dir to the end of the MEDIA_URL, but it's not doing that. I've tried a lot of variations of beginning/ending slashes but it doesn't help. Am I missing something obvious here? Should it work as intended on the dev server? Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Creating one call for most recent entry, and another call for the rest
I have just set up a blog using the helpful tutorial over at http://fallingbullets.com/blog/2006/aug/06/wordpress-clone-27-seconds-part-1-40/";>Falling Bullets, and now I am looking to do a little customization. I am completely new to Django and Python, so if this question seems simple, forgive my niavete. Here is the code I have for the main page of the blog: {% extends "base.html" %} {% block title %}Latest Blog Entries{% endblock %} {% block content %}Latest Blog Entries
{% for object in latest %}
{% endblock %} Instead of just having this list of blog entries, it would be great if I could have two different calls, one that asked for the most recent post and then a second that would list the rest of the posts. I want to style the first post in a completely different manner than the rest. Is there a simple way to do this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---- {% endfor %}
{{ object.title|escape }}
{{ object.pub_date|date:"F j, Y" }}
{{ object.summary }}
Creating one call for most recent entry, and another call for the restI have just set up a blog using the helpful tutorial over at
I have just set up a blog using the helpful tutorial over at http://fallingbullets.com/blog/2006/aug/06/wordpress-clone-27-seconds... and now I am looking to do a little customization. I am completely new to Django and Python, so if this question seems simple, forgive my niavete. Here is the code I have for the main page of the blog: {% extends "base.html" %} {% block title %}Latest Blog Entries{% endblock %} {% block content %}Latest Blog Entries
{% for object in latest %}
{% endblock %} Instead of just having this list of blog entries, it would be great if I could have two different calls, one that asked for the most recent post and then a second that would list the rest of the posts. I want to style the first post in a completely different manner than the rest. Is there a simple way to do this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---- {% endfor %}
{{ object.title|escape }}
{{ object.pub_date|date:"F j, Y" }}
{{ object.summary }}
Re: Creating one call for most recent entry, and another call for the restI have just set up a blog using the helpful tutorial over at
Do I need to include {% for object in latest %}? Or, does this replace it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating one call for most recent entry, and another call for the restI have just set up a blog using the helpful tutorial over at
Okay, so I've put in that code and it processes it fine and everything, however, all the entries are being placed in the else section, the filter for counter "1" doesn't seem to be grabbing the latest article. Is there another filter that could maybe grab it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating one call for most recent entry, and another call for the restI have just set up a blog using the helpful tutorial over at
PS the site is main.howcurio.us/blog --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating one call for most recent entry, and another call for the restI have just set up a blog using the helpful tutorial over at
http://paste.e-scribe.com/2598/ Check it out! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating one call for most recent entry, and another call for the restI have just set up a blog using the helpful tutorial over at
It doesn't seem to be working, or at least it hasn't yet come out that way. I made another attempt where I essentially left out the {else} and nothing at all rendered, so that filter doesn't seem to be catching it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating one call for most recent entry, and another call for the restI have just set up a blog using the helpful tutorial over at
Hazaa, that seemed to have done the trick. When I have a second, I'll try to debug the sucker too, that way we can have some closure on your method, Rajesh. Thank you both for your help! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating one call for most recent entry, and another call for the restI have just set up a blog using the helpful tutorial over at
Rajesh, I added in the counter and it popped out "1" for the first entry, so I am unsure why your method didn't work. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating one call for most recent entry, and another call for the restI have just set up a blog using the helpful tutorial over at
It's namely the second I'm worried about. I have an ordered list and I want the first entry to have a special style, something to the degree of "new content." I want to target the second one because I want it to start the "old content" section, with a different style, like a fade on top, or something like that. I could care less about the tenth entry, I was just commenting that the loop allows you to target only the first and last, and I wanted to know how to hit anything in between. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Looking for a Senior Django Application Developer
All, Sorry to bug the group with an open position - but thought it was worth a try. I am looking for a senior Django application developer for a year long contract in DC at a major media company. I've posted the complete job requisition below, but what we really need is a super solid senior person who know Python/Django inside and out. The hourly rate would be around $80/hr. You would be required to be on-site in NW DC a couple of days/week (probably like 3), although some of the work could be done remotely. Please let me know if you are interested. Thanks, Andy Nussbaum anussb...@aajinteractive.com = *Python/Django Developer* Our client is a well known brand name company in the consumer media industry. For this client we are looking for a Python/Django application developer to help build out their existing web site, and support the creation of new functionality. The ideal candidate will have experience working with consumer facing websites, would not be afraid of Web Services, and has experience with CMS’s. The ideal candidate should be comfortable working within a team, as well as working independently to develop great code. This is a yearlong contract position (2013) for a senior Django application developer to work closely with our clients’ chief Applications architect on their core architecture supporting their Content Management Systems and Membership platforms. Experience: - Python, Django, Linux/UNIX, PostgreSQL, vi editors, Jira, AJAX, JQuery, Perl - Successful design, implementation, deployment and maintenance of high-traffic multi-server environment - Actively participation in design and code reviews - Ability to troubleshoot and fix production issues - Development of new software to support business initiatives - A high degree of initiative and the ability to work independently - The Senior Application Developer will contribute to application solutions. Selected candidate must have strong web development and software architecture skills, and be highly collaborative in exciting and agile project environments - Provide early architectural feedback on feasibility and estimation of business requirements in conjunction with architect. - Push code deployments to production - Develop Django web applications to meet stated business requirements. - Participate in peer reviews, critiques, and knowledge sharing by pushing the boundaries in application development. - Maintain existing content management systems, including technical troubleshooting to diagnose production or application issues. - BS/BA degree in Computer Science, Information Technology, Software Engineering or related field, or equivalent work experience with a minimum of five (5) years of experience. - Exceptional experience and proficiency with the Django framework, utilizing both Python and PostgreSQL or MySQL databases. - Knowledgeable about the latest trends in application development, including python packages, message queues, GIS and NoSQL databases, continuous integration testing, building solution stacks from front to back, multilayer caching methods, API's, and device-specific solutions. - The ability to write clean, well-documented code. - The ability to work on multiple concurrent projects is essential. Strong self motivation and the ability to work with minimal supervision. - Experience working on large-scale web media-based solutions, especially in regards of scaling large production environments. - Must be a team-oriented individual, energetic, result & delivery oriented, with a keen interest on quality and the ability to meet deadlines. Selected candidate will be required to handle multiple tasks simultaneously, and requires the ability to accurately gauge project duration, deliver on deadlines, and switch rapidly between projects in a fast paced environment. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/cK19Tj5jqRMJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Looking to hire a great team of Python/Django developers
All, We have a really cool project in Washington DC. We'll be putting together a team of developers (some contract, some full time employees of our client) for this effort. Very cool place doing consumer facing web development. Brand name company - interesting content. Need some great knowledgeable folks who want to work in DC (NW), and push the cutting edge of the technology. Let me know if you're interested, and I'll be happy to forward you the complete job details, Andy Nussbaum AAJ Interactive Technologies -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[JOB] Looking for a bunch of great Python/Django developers to work in the District
We are looking to add a bunch of great Python (would be great if they have solid Django skills) developers to our direct clients team in Northwest DC (not far from Metro Center). This is not some boring government contract, this is a cool company in the Media space, doing great consumer facing stuff on the web. We really need super solid Python folks who have a solid understanding of Object Oriented development. Our firm is not like all the big body shops/head hunting firms. We are a small nitche contracting/consulting/placement company that does almost all of our work in the local DC area - and most of the work is in the Media/Web space. These jobs are mostly full time employee positions working directly for our client, but they can also be contract, or temp-to-hire ... but all will require you to be on-site almost full time in the district. Below is the more formal job req - but you know who you are. If you're a great Python developer, looking to do cool web development, on a site that will be viewed by a ton of people (one you'll be excited to tell people you are working for), then you should get back to me asap. Hope to hear from you soon, Andy Nussbaum Partner AAJ Interactive Technologies www.aajinteractive.com j...@aajinteractive.com === *Python/Django Developers* Our client is a well known brand name company in the consumer media industry. For this client we are looking for Python/Django application developers to help build out their existing web site, and support the creation of new functionality. The ideal candidate will have experience working with consumer facing websites, would not be afraid of Web Services, and has experience with CMS’s. The ideal candidate should be comfortable working within a team, as well as working independently to develop great code. These are full time employee positions working directly as an employee of our client. There is also the opportunity to contract, and/or go contract to hire. However, all positions require the developers to be on-site full time. Some remote work is possible in the future, but the majority of the work will need to be done on-site at the clients facilities in NW DC. Experience: - Python, Django, Linux/UNIX, PostgreSQL, vi editors, Jira, AJAX, JQuery, Perl - Successful design, implementation, deployment and maintenance of high-traffic multi-server environment - Actively participation in design and code reviews - Ability to troubleshoot and fix production issues - Development of new software to support business initiatives - A high degree of initiative and the ability to work independently - The Application Developer will contribute to application solutions. Selected candidate must have strong web development and software architecture skills, and be highly collaborative in exciting and agile project environments - Provide early architectural feedback on feasibility and estimation of business requirements in conjunction with architect. - Push code deployments to production - Develop Django web applications to meet stated business requirements. - Participate in peer reviews, critiques, and knowledge sharing by pushing the boundaries in application development. - Maintain existing content management systems, including technical troubleshooting to diagnose production or application issues. - BS/BA degree in Computer Science, Information Technology, Software Engineering or related field, or equivalent work experience with a minimum of two (2) years of experience. - Exceptional experience and proficiency with the Django framework is nice to have, utilizing both Python and PostgreSQL or MySQL databases. - Knowledgeable about the latest trends in application development, including python packages, message queues, GIS and NoSQL databases, continuous integration testing, building solution stacks from front to back, multilayer caching methods, API's, and device-specific solutions. - The ability to write clean, well-documented code. - The ability to work on multiple concurrent projects is essential. Strong self motivation and the ability to work with minimal supervision. - Experience working on large-scale web media-based solutions, especially in regards of scaling large production environments. - Must be a team-oriented individual, energetic, result & delivery oriented, with a keen interest on quality and the ability to meet deadlines. Selected candidate will be required to handle multiple tasks simultaneously, and requires the ability to accurately gauge project duration, deliver on deadlines, and switch rapidly between projects in a fast paced environment. If this sounds like you, please respo
Need to hire a Senior Django Web Architect
All, We have a great client in downtown DC. They need a Django architect to help them. Our client is a well known brand name company in the consumer media industry. The ideal candidate will have experience working with consumer facing websites, would not be afraid of Web Services, and has experience with CMS’s. The ideal candidate should be comfortable working within a team, as well as working independently to develop a solution. This would be a full time employee position working directly for our client. The salary level is $120,000 - $140,000/yr. Please let me know if you're interested, and we can chat. Sincerely, Andy Nussbaum Our client is looking for qualified candidates for a Web Architect position. The successful candidate will be a charismatic leader and passionate web architect with a proven track record building highly scalable Internet-based products. You will be responsible for driving the rapid evolution of our clients' software architecture for Search, Video, Content Management and Registration. The position is part of a proven team of architects that is looking to increase its depth. Please consider applying even if you are not knowledgeable in all areas mentioned below. *Responsibilities:* - Define architecture for web enabled systems including CMS, Search, Streaming Video, Identity Management and Community. - Integrate internal and external systems. Provide leadership on cloud based strategy. - Define Service Oriented Architecture (SOA) and RESTful APIs to expose content, authentication, community, and messaging services for internal and 3rd party developers. - Working with the development team, the hire will develop and maintain a roadmap of architectural improvements and API rollouts. - Evaluate and work closely with 3rd party development companies. *Experience:* Undergraduate degree in Computer Science, Information Technology, Software Engineering or similar field desired. - 8 years work experience in progressively responsible technical role. - Extensive experience with service oriented architectures. - Experience supporting a media business is a plus *Knowledge and Skill Requirements:* 8+ years total relevant experience Defining systems architecture with emphasis on integrating existing systems and web-based services Building products that get deployed and scale Recognized as an expert practitioner 3+ years of hands-on experience as an system architect Experience with: - Building software development environments that work - Python and Django experience - API Definition and deployment - Experience with Registration , SAML, oAuth and Active Directory. - Experience with CMS systems - Search, including Elastic Search - Streaming video experience a plus - Partner integration through open and proprietary Internet interfaces - Content and data migration - Ability to instill a culture of friendly competitiveness that drives high quality and few software defects - Excellent communication and writing skills - Understandable by non-technology staff - Presentable to partners and clients -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Where are request.user defined and assigned?
I'm trying to understand how does request.user work. Looking into the source code of the HttpRequest class (https:// code.djangoproject.com/browser/django/trunk/django/http/ __init__.py#L135) there is no "user" attribute for HttpRequest. So where is the "user" attribute defined? And which code is responsible to assign an User instance to that attribute? Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Where are request.user defined and assigned?
Thank you. So LazyUser is there to cache the user instance. In LazyUser(object), the user instance is stored in request._cached_user In AuthenticationMiddleware(object), the user instance is stored in request.__class__.user But I don't see request.user being assigned at all. Where does that happen? So what are the differences between the following three: request._cached_user request.__class__.user request.user Why have 3 different user attributes? I'm confused. Thanks. On May 10, 3:39 pm, Shawn Milochik wrote: > The User model is in django.contrib.auth, not in the core of Django. > > request.user is dealt with in the middleware that comes with the auth > module. > > http://code.djangoproject.com/browser/django/trunk/django/contrib/aut... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.