Use Python to parse HTML and integrating said script into Django
Hi I'm not too sure how to ask this correctly (not an experienced developer so my vocab is not very accurate), but I'll try. I have created a Python script (collection of functions) that generates a calendar of sorts, really just a long list of dates from a 4 year date range. It also parses the HTML, as I couldn't work out how to do this with the limited logic available the templating language. My question are: Is it possible to use a "freeform" python within the Django framework, and yet let it receive arguments from the model? I was intially thinking of making a custom view, but then I have all this parsed HTML and am not sure how to get it into a template. Or should I be looking at making a custom tag? If not the above, do you have any other pointers on how to go about 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-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: Business Logic Architecture Questions on Models & ModelManagers
Hey Malcolm, Thank you very much for your thoughts on those questions! I will definitely be referring to your advice when I'm writing this thing. I had been thinking about those questions when I was on spring break (about a week or so) and couldn't seem to reach a conclusion, but, I think I'll be a bit better off now. Thank you again. -Sean On Apr 12, 11:16 pm, Malcolm Tredinnickwrote: > On Sun, 2009-04-12 at 20:41 -0700, Sean Neilan wrote: > > I'm building a large web application & I'm trying to figure out ways > > to organize my business logic (just the queries). I figure I should > > either put all my queries inside Model functions or ModelManager > > functions. I've searched all over the internet for documentation on > > where the business logic goes, but, didn't find what I was looking > > for. > > > I have a couple questions: > > Opinions vary a bit on these sorts of things. What follows are mine... > > > > > 1) Should Model methods not contain any queries? Only calculations > > based on the attributes of that model. Much like > >http://docs.djangoproject.com/en/dev/topics/db/models/#id4 > > When you have a model instance, it represents a single row in the > database. Methods on a Python class instance tend to act on that > instance, so it makes sense to have model methods act on the particular > data for that instance, not be more general. > > Now, it could well be that "acting on the instance" really means > "related to that instance" and does other queries to pull in > information. For example, my blog code currently has the world's lamest > tagging system (a very simple tag model with a name and a pointer to > itself for the parent) and I have methods on the model that are "get all > the descendents of this instance" and "get the ancestors of this > instance". They are methods that are specific to the instance at hand. > > > > > 2) Is it a good idea to encapsulate _all_ queries as methods inside of > > a manager class? Thus making it slightly easier to reuse queries. > > Abstracting everything to the n-th degree can often make code a lot > harder to read, so curb your enthusiasm a little bit here. > > Model managers tend to be a good place to put methods that act on the > collection of model instances. For example, using my lame tag example > again, a method to query all the tags matching a particular name prefix. > The documentation describes these as table-level methods, which tends to > be the way I've thought of them over the years. > > For genuinely reusable query fragments, I find myself writing normal > Python functions that accept a queryset as an argument. Then they aren't > tied to any particular model, although I have some implicit contract > with myself (as the user of those functions) that they querysets I pass > in will be for objects that, say, have a "title" attribute so I can > filter on the title. > > I will point out that some people like using classmethods for this sort > of stuff. For model class-level queries -- the table-level stuff -- I > find this looks very odd in code. It's one of those cases of not looking > like almost all other Django code. > > In general, I'm fairly negative about classmethods in Python, though, > since they're fairly unnecessary as Python already has ample namespacing > capabilities. Other languages have classmethod equivalents because > they're namespacing isn't as good. So you won't see me using classmethod > style operations and there's swearing involved when I have to use > somebody else's code that does (something that's happening in a > side-project at the moment -- the other app is making my code looking > fugly!) > > > > > 3) Is it a bad thing if a query inside of a Manager function uses > > filter() to join with or even return another object type/list? This > > obviously couples the query to the name of a model, but, also couples > > the manager to an object that it doesn't manage. (The object that it > > doesn't manage being joined in the query.) > > Trying to frame things as "bad" or "good" is probably not going to help > very much, since it leads to discussions about what is really bad or > good. I personally don't write things like that, since I like my > managers methods on model X to returns things about model X. > > However, I'm not a slave to "everything must be in a class" and normal > Python module-level functions are my good friends. So if I'm got > something that is related to model X and returns something that isn't a > queryset, I'll often just make it a function. The import statements > elsewhere in the code namespace it usefully and using the function is > pretty easy and not overly verbose. > > > 4) Also, Is it possible for a ModelManager object to gain access to > > request.user so that the objects returned depend on who's logged in? > > Not unless you pass it in. Models are completely independent of the > request/response cycle. They are only concerned with the persistent > storage of
Re: newbie question: django-registration
You should change the site domain name example.com to 127.0.0.1:8000 check in your django-site table.. http://www.example.com/accounts/activate/ 637cd08106eea9b1139efd34a0fa79a5d7f90494/ for instance http://127.0.0.1:8000/accounts/activate/ 637cd08106eea9b1139efd34a0fa79a5d7f90494/ On Apr 13, 12:55 am, Angel Cruzwrote: > Eh, > Never mind. Something is wrong with my root url (fixing the link from the > email activated the account). > > I will fix it. > > On Sun, Apr 12, 2009 at 12:21 PM, MrBodjangles wrote: > > > Hi Folks and Happy Easter! > > > OK, making slow but sure progress on learning Django. > > > I am using django-registration, have provided the simple templates > > required, and am to the point that a user can register (their usename, > > password, etc. get populated in the auth_user table of the PostgreSQL > > databae I am using), and receives an email. > > > I am stuck on the activation. > > > When I check my email and click on the link, I receive the following: > > "The requested URL /accounts/activate/ > > 637cd08106eea9b1139efd34a0fa79a5d7f90494/ was not found on this > > server" > > > I had assumed that the /accounts/activate/ folder > > would have been automatically generated? > > > I added this line to my URLConf, thinking this was the reason: > > (r'^accounts/activate// > > $','registration.views.activate'), > > > What step am I missing? > > > Advanced 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: Registration form and Profile form is not saving
How the current user logging-in first while registration.. you mean to say after successfully registration the user must login automatically. On Apr 11, 7:55 pm, Praveenwrote: > Hi all, i am really fed up and have tried number of way. Please read > my last line which really describe where i am facing problem. > First Attempt. > models.py > - > class UserProfile(models.Model): > user = models.ForeignKey(User, unique=True, verbose_name=_ > ('user')) > gender = models.CharField(_('gender'), max_length=1, > choices=GENDER_CHOICES, blank=True) > dob = models.DateField(_('dob'), max_length=10, help_text=_ > ("Should be in date format"), null=True, blank=True) > city = models.CharField(_('res_city'), max_length=30, > choices=CITY_CHOICES, blank=True) > > class RegistrationForm(forms.Form): > """The basic account registration form.""" > title = forms.CharField(max_length=30, label=_('Title'), > required=False) > email = forms.EmailField(label=_('Email address'), > max_length=75, required=True) > password2 = forms.CharField(label=_('Password (again)'), > max_length=30, widget=forms.PasswordInput(), required=True) > password1 = forms.CharField(label=_('Password'), > max_length=30, widget=forms.PasswordInput(), required=True) > first_name = forms.CharField(label=_('First name'), > max_length=30, required=True) > last_name = forms.CharField(label=_('Last name'), > max_length=30, required=True) > #gender = forms.CharField(label = _('Gender'), widget = > forms.Select(choices=GENDER_CHOICES,attrs=attrs_dict)) > #dob = forms.DateTimeField(widget=forms.DateTimeInput(attrs=dict > (attrs_dict, max_length=75)), label=_(u'date of birth')) > #city = forms.CharField(label = _('res_city'), widget = > forms.Select(choices=CITY_CHOICES,attrs=attrs_dict)) > > def __init__(self, *args, **kwargs): > self.contact = None > super(RegistrationForm, self).__init__(*args, **kwargs) > > newsletter = forms.BooleanField(label=_('Newsletter'), > widget=forms.CheckboxInput(), required=False) > > def clean_password1(self): > """Enforce that password and password2 are the same.""" > p1 = self.cleaned_data.get('password1') > p2 = self.cleaned_data.get('password2') > if not (p1 and p2 and p1 == p2): > raise forms.ValidationError( > ugettext("The two passwords do not match.")) > > # note, here is where we'd put some kind of custom > # validator to enforce "hard" passwords. > return p1 > > def clean_email(self): > """Prevent account hijacking by disallowing duplicate > emails.""" > email = self.cleaned_data.get('email', None) > if email and User.objects.filter(email=email).count() > 0: > raise forms.ValidationError( > ugettext("That email address is already in use.")) > > return email > > def save(self, request=None, **kwargs): > """Create the contact and user described on the form. Returns > the > `contact`. > """ > if self.contact: > log.debug('skipping save, already done') > else: > self.save_contact(request) > return self.contact > > def save_contact(self, request): > print " i am in save_contact " > log.debug("Saving contact") > data = self.cleaned_data > password = data['password1'] > email = data['email'] > first_name = data['first_name'] > last_name = data['last_name'] > username = data['title'] > #dob = data['dob'] > #gender = data['gender'] > #city = data['city'] > > verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == > 'EMAIL') > > if verify: > from registration.models import RegistrationProfile > user = RegistrationProfile.objects.create_inactive_user( > username, password, email, send_email=True) > else: > user = User.objects.create_user(username, email, password) > > user.first_name = first_name > user.last_name = last_name > user.save() > > # If the user already has a contact, retrieve it. > # Otherwise, create a new one. > try: > contact = Contact.objects.from_request(request, > create=False) > #profile = UserProfile.objects.form_request(request, > create=False) > except Contact.DoesNotExist: > contact = Contact() > > contact.user = user > contact.first_name = first_name > contact.last_name = last_name > contact.email = email > contact.role = 'Customer' > contact.title = data.get('title', '') > contact.save() > > if 'newsletter' not in data: > subscribed = False > else: > subscribed
Re: how to use email instead of username for user authentication?
Malcolm, <- Remembered the 'l' this time! To keep things simple and avoid fragmenting this discussion into a million different dead end tit for tats , I'll try to reign in the main points. 1. The default authentication method in Django should have no inherent restrictions. Such as blocking '@' in the username. This leaves the default framework open and free of workarounds. This approach would not preclude any project specific requirements. 2. Any authentication method having restrictions should be an opt in method. The current method is a restrictive authentication method, one that does not allow email, and should be made optional. 3. When you boil down the hundreds of specific use cases out there you still end up with the above two points. In which case I would make the argument that if you need to block emails as user names then it is you who should write a new authentication handler. In your own words, the framework allows this and its only a few lines of code. Now for the dead end tit for tat... this is really project philosophy not framework philosophy... hence I feel like it is circular discussion that distracts from the main point... Authenticating by email does not require me to check my email every time I log in. So if my email is no longer accessible (left my job) I can simply log in and change it to a new one. If changing the username requires checking my email then I will have the same problem if I use email as my username or not. You yourself identify the username as mainly an authentication mechanism not necessarily a display value. Thats all the more reason to have a robust restriction free out of the box implementation of authentication. Thanks for reading the feedback, I still fail to see how you can include project specific requirements in a framework? The implementation you are advocating is a subset of the general implementation I would like to see bundled out of the box. Why not move it into an optional module? -Paul On Apr 11, 4:13 pm, Malcolm Tredinnickwrote: > On Sat, 2009-04-11 at 07:52 -0700, pkenjora wrote: > > Malcom, > > Well, I'm not "Malcom" (sic), but I'll reply anyway. > > > Google, FaceBook, and LinkedIn have been using email authentication > > for how long now? With the default constraints you've put on Django a > > developer would have to "work around" the out of the box code to make > > the project behave like the big 3 names on the web. > > There's some assumption there that what they're doing is a good idea. > Their systems have the usability problems I've mentioned. It's also not > clear their authentication methods are the best around. In any case, as > I note below (and have written elsewhere), you're simply not restricted > from using this system and can do so without patching Django, if that's > the way you want to go. There's no restriction in place here! > > The combined size of forums and social networking sites not pretending > that my "handle" is an email address is, I'll wager, larger than > Facebook or LinkedIn, certainly. Which has precisely the same small > weight as your examples. The point being that there are valid use-cases > in both directions and you'll notice that that's never been disputed. > > [...] > > > As far as your reasons go, I'm fairly sure its just as easy to > > change the email as it is the username, > > I'm sorry you feel that way. It's patently false. The username is only > used on the site you are creating an account for. Your email address has > much wider usage and creating a new one isn't always possible or > desirable (signing up to one of the hosted services requires agreeing to > T that are often unpleasant). The username when creating a new account > on a site has much less currency. > > > I would even argue that my > > username (display name) could change but my login credentials should > > stay the same. > > You are assuming that the username is the display name. That might be a > secondary use for it and it sometimes works well for that. However, the > username is primarily the unique identifier for the user within the > system. It's the thing that won't change. Having a display name, > particularly one that can change is also quite common and it's for > extensions like that that user profile exist for. > > Login credentials are not the same as identifier within the system. The > login credentials should definitely be permitted to change. Having an > account tied to an email address is tragic when that email address is no > longer accessible to you (for example, it was a company address and > you've since left the company). Allowing the email address to change -- > and hence not making it the entity identifier -- is a good thing. > > > You are correct, username authentication has always been around. > > However, the explicit banning and obfuscating of email authentication > > in the default module has not. > > I'm sorry, but that's simply not correct. I pointed
Re: Business Logic Architecture Questions on Models & ModelManagers
On Sun, 2009-04-12 at 20:41 -0700, Sean Neilan wrote: > I'm building a large web application & I'm trying to figure out ways > to organize my business logic (just the queries). I figure I should > either put all my queries inside Model functions or ModelManager > functions. I've searched all over the internet for documentation on > where the business logic goes, but, didn't find what I was looking > for. > > I have a couple questions: Opinions vary a bit on these sorts of things. What follows are mine... > > 1) Should Model methods not contain any queries? Only calculations > based on the attributes of that model. Much like > http://docs.djangoproject.com/en/dev/topics/db/models/#id4 When you have a model instance, it represents a single row in the database. Methods on a Python class instance tend to act on that instance, so it makes sense to have model methods act on the particular data for that instance, not be more general. Now, it could well be that "acting on the instance" really means "related to that instance" and does other queries to pull in information. For example, my blog code currently has the world's lamest tagging system (a very simple tag model with a name and a pointer to itself for the parent) and I have methods on the model that are "get all the descendents of this instance" and "get the ancestors of this instance". They are methods that are specific to the instance at hand. > > 2) Is it a good idea to encapsulate _all_ queries as methods inside of > a manager class? Thus making it slightly easier to reuse queries. Abstracting everything to the n-th degree can often make code a lot harder to read, so curb your enthusiasm a little bit here. Model managers tend to be a good place to put methods that act on the collection of model instances. For example, using my lame tag example again, a method to query all the tags matching a particular name prefix. The documentation describes these as table-level methods, which tends to be the way I've thought of them over the years. For genuinely reusable query fragments, I find myself writing normal Python functions that accept a queryset as an argument. Then they aren't tied to any particular model, although I have some implicit contract with myself (as the user of those functions) that they querysets I pass in will be for objects that, say, have a "title" attribute so I can filter on the title. I will point out that some people like using classmethods for this sort of stuff. For model class-level queries -- the table-level stuff -- I find this looks very odd in code. It's one of those cases of not looking like almost all other Django code. In general, I'm fairly negative about classmethods in Python, though, since they're fairly unnecessary as Python already has ample namespacing capabilities. Other languages have classmethod equivalents because they're namespacing isn't as good. So you won't see me using classmethod style operations and there's swearing involved when I have to use somebody else's code that does (something that's happening in a side-project at the moment -- the other app is making my code looking fugly!) > > 3) Is it a bad thing if a query inside of a Manager function uses > filter() to join with or even return another object type/list? This > obviously couples the query to the name of a model, but, also couples > the manager to an object that it doesn't manage. (The object that it > doesn't manage being joined in the query.) Trying to frame things as "bad" or "good" is probably not going to help very much, since it leads to discussions about what is really bad or good. I personally don't write things like that, since I like my managers methods on model X to returns things about model X. However, I'm not a slave to "everything must be in a class" and normal Python module-level functions are my good friends. So if I'm got something that is related to model X and returns something that isn't a queryset, I'll often just make it a function. The import statements elsewhere in the code namespace it usefully and using the function is pretty easy and not overly verbose. > 4) Also, Is it possible for a ModelManager object to gain access to > request.user so that the objects returned depend on who's logged in? Not unless you pass it in. Models are completely independent of the request/response cycle. They are only concerned with the persistent storage of data (not even necessarily business rules -- they're not the capital-M, MVC models). Request.user isn't a data storage thing. > Perhaps, if this is not a good design pattern (coupling the > authentication mechanisms to the ModelManager), should I simply take a > User object as a parameter on the ModelManager functions? I prefer that approach. Explicit over implicit. Some people shove request.user into threadlocals and use that. I personally don't like it, but I've used it from time to time as a last resort (or because the existing code did). The problem there is that
Business Logic Architecture Questions on Models & ModelManagers
I'm building a large web application & I'm trying to figure out ways to organize my business logic (just the queries). I figure I should either put all my queries inside Model functions or ModelManager functions. I've searched all over the internet for documentation on where the business logic goes, but, didn't find what I was looking for. I have a couple questions: 1) Should Model methods not contain any queries? Only calculations based on the attributes of that model. Much like http://docs.djangoproject.com/en/dev/topics/db/models/#id4 2) Is it a good idea to encapsulate _all_ queries as methods inside of a manager class? Thus making it slightly easier to reuse queries. 3) Is it a bad thing if a query inside of a Manager function uses filter() to join with or even return another object type/list? This obviously couples the query to the name of a model, but, also couples the manager to an object that it doesn't manage. (The object that it doesn't manage being joined in the query.) 4) Also, Is it possible for a ModelManager object to gain access to request.user so that the objects returned depend on who's logged in? Perhaps, if this is not a good design pattern (coupling the authentication mechanisms to the ModelManager), should I simply take a User object as a parameter on the ModelManager functions? (I'm asking this question because perhaps there's a better way to couple the authentication mechanism or User object to the ModelManager) Thank you for your time. --Sean Neilan http://seanneilan.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 -~--~~~~--~~--~--~---
Re: Question about administration
On Sun, Apr 12, 2009 at 9:31 PM, Joshua Williamswrote: > That was the nugget I was looking for. I think that my use case falls > into the latter, which is currently not available. Good news is, as > long as i only support 1 "working area" i should be ok. It's true that there's no "push this button and it magically works that way" option. However, setting up something like "Mary can only edit her own stories" is actually pretty easy if you just tweak a couple things on your ModelAdmin subclass: http://www.b-list.org/weblog/2008/dec/24/admin/ -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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: Question about administration
Thank you pointing me to these docs. In the link: > If that doesn't tickle your fancy, check out the following: > http://docs.djangoproject.com/en/dev/topics/auth/#permissions I found the following statement: For example, it's possible to say "Mary may change news stories," but it's not currently possible to say "Mary may change news stories, but only the ones she created herself" or "Mary may only change news stories that have a certain status, publication date or ID." The latter functionality is something Django developers are currently discussing. That was the nugget I was looking for. I think that my use case falls into the latter, which is currently not available. Good news is, as long as i only support 1 "working area" i should be ok. -Karlw On Apr 12, 2009, at 3:24 PM, Jacolyte wrote: > > On Apr 12, 8:16 am, Karlwwrote: >> Hey all, >> >> I had a general question about administration in Django. So I do not >> think my situation is unique, so I don't want to go out and make a >> customer solution if there is already something out there. >> >> What i would like to have happen would be to separate my site into >> "working areas", and each working area only has the ability to >> interact with other items in their area. This would keep a user in >> area 1 from interacting with a user in area 2, and furthermore admins >> from doing the same. >> >> A way that I know how to do this would be to roll out a new django >> project for each "working area". But have the "working area" >> solution >> that i have in my head seems to be a bit more elegant. You would >> update the views/models on 1 project instead of having to script a >> deployment across several. >> >> Is there some django app that already has this built in? Any info >> would be helpful. >> >> Best Regards, >> >> Karlw > > If I understood you correctly, you just want to restrict areas of a > website, such as apps or certain models. If that's the case, check out > the following snippet: > http://www.djangosnippets.org/snippets/334/ > > If that doesn't tickle your fancy, check out the following: > http://docs.djangoproject.com/en/dev/topics/auth/#permissions > > and > http://docs.djangoproject.com/en/dev/ref/models/options/#permissions > > --~--~-~--~~~---~--~~ 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: Mulitple Time Zone support?
On Apr 12, 7:15 pm, ydjangowrote: > What is the best way to provide multiple Time zone support? Definitely check out the Python pytz module. > (Also where can I get list of all time zones to populate the select > dropdown.) > There is almost 400 time zones in the "common timezones" in pytz. The timezones are of the forum "area/city", so I created a drop down for area and then a 2nd drop down for city (with Javascript that populates the city based on the area chosen). That's still a lot of timezones to choose from but it was better than having 400 in one list. --~--~-~--~~~---~--~~ 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: Simple Query?
On Sun, Apr 12, 2009 at 8:24 PM, jrs_66wrote: > > Thanks Karen, > > models are as follows... > > class MediaAndContainer(models.Model): >media = models.ForeignKey(MediaLocal) >order = models.FloatField(null=True, blank=True) >... > > class MediaLocal(models.Model): >name = models.CharField(max_length=255, blank=True) >height = models.IntegerField(null=True, editable=False) >width = models.IntegerField(null=True, editable=False) >... > > I'm trying to get everything from the MediaLocal model and the 'order' > field from the MediaAndContainer model... > For which you were trying: media = MediaLocal.objects.select_related('order').filter( mediaandcontainer__media__exact = 1 ) and expecting media.order to then exist. What you are trying has a few problems. First, select_related('order') on a MediaLocal QuerySet doesn't do anything, since MediaLocal doesn't have 'order' as a ForeignKey field. (I'm a little surprised it doesn't raise an error.) At any rate, be aware select_related is purely a performance optimization, and does not affect what related objects you can access from your Python code -- it just affects how many SQL queries are executed under the covers when you actually access the related objects. For reference, the complete doc for select_related is here: http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4. Second, 'media' in the above code is the result of filter() on a QuerySet, and thus is a QuerySet itself (see http://docs.djangoproject.com/en/dev/ref/models/querysets/#queryset-methods-that-return-new-querysets). Trying to access something like media.order implies you are trying to treat the filter() result as an instance of one of your model objects, but it won't be, it will be a QuerySet. If you want a model instance, you need to retrieve a specific instance from a QuerySet, possibly by using get() instead of filter(). Third, as you have these models defined, any particular MediaLocal instance may have many associated MediaAndContainer instances pointing to it. So there are potentially many MediaAndContainer.order values for a given MediaLocal instance. Yet your question seems to imply there is only one? So I'm confused. In case it helps, I'll note you can access the set of MediaAndContainer.order values for a given MediaLocal instance via the order_set attribute of a MediaLocal model instance. So if you had: media = MediaLocal.objects.get(pk=1) then you could iterate through media.order_set.all() and get the related MediaAndContainer instances, each with its own order field. But since you seem to be expecting to be able to get a single order value, I'm not sure these models are accurately reflecting your data. Perhaps your media ForeignKey in the MediaAndContainer model should be a OneToOneField ( http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield) instead? Or possibly you have the ForeignKey in the wrong model, I'm not sure. (BTW the 'pk=1' above is, I believe, equivalent to what you were trying to get at with 'mediaandcontainer__media__exact = 1', see http://docs.djangoproject.com/en/dev/topics/db/queries/#the-pk-lookup-shortcut. I am not sure why you were using the much longer version?) Karen --~--~-~--~~~---~--~~ 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: Fwd: Default ManyToMany ordering
If it's for the admin interface the admin option ordering (http:// docs.djangoproject.com/en/dev/ref/contrib/admin/#ordering) might do the trick. --~--~-~--~~~---~--~~ 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: Simple Query?
The easiest answer is your foreignkey is pointing the wrong way. With your current model definitions you could do MediaAndContainer.objects.select_related('name'). To go in the opposite direction you need to use _set (http://docs.djangoproject.com/ en/dev/topics/db/queries/#following-relationships-backward) to go backwards; or restructure your model. --~--~-~--~~~---~--~~ 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: Send validation error message to the screen
On Sun, 2009-04-12 at 17:22 -0700, Joshua Partogi wrote: > Thanks Malcolm, > > What I'm looking after is sending my custom validation error message > that is not covered by django. But what does this mean? How is it different from passing any other piece of information to a template via the context you pass to Template.render() or render_to_response()? I'm still not understanding what the problem is here. Regards, Malcolm --~--~-~--~~~---~--~~ 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: Mulitple Time Zone support?
On Sun, 2009-04-12 at 17:15 -0700, ydjango wrote: > What is the best way to provide multiple Time zone support? > > The registered user visiting the website should see all times and > dates as per his/her time zone and not as per time zone in > settings.py? If I were doing this, I'd create a templatetag that formats the datetime object into the appropriate timezone. You could use, say, a context processor or some consistent thing you call from your views to populate the context with the user's timezone. You could also use a filter for this, although the design has to be slightly different. Filters are unaware of the template they're rendering in, so they don't have access to the context. Therefore, you'd have to pass the appropriate timezone (or an object containing the timezone) to the filter as an argument. So it's a choice between a couple of possibilities, at least: (1) {% tz_convert obj as obj2 %} Accepts "obj" (a date or datetime object), uses something in the context to work out the timezone and then creates a new object in the context ("obj2") that you can use later and which has the right timezone value. (2) {{ obj|tz_convert:tz }} Converts a date or datetime object to an equivalent object in the right timezone, the timezone being passed in via the "tz" variable, in this case. I can imagine either solution being more appropriate than the other in different circumstances, so I'd just go for whichever approach seems best, rather than worrying too much about whether there's a single best answer here. There's no doubt other possibilities as well; the above were the two I could come up with quickly that seem to hold up against a few hypothetical usages I threw at them. Regards, Malcolm --~--~-~--~~~---~--~~ 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: Simple Query?
On Sun, 2009-04-12 at 14:06 -0700, jrs_66 wrote: [...] > On a broader level, is Django's ORM intended for people who don't know > how to write SQL? It seems that many hoops have to be jumped through > to get basic SQL results... I think that impression is probably only because you're still learning Django. Simple SQL queries are generally very simple querysets and even complex SQL queries are relatively simple querysets (that's where the ORM really comes into it's own, because the complexity of SQL increases rapidly, whilst the corresponding queryset expression remains as a straightforward series of changed filters and annotations). That being said, Django isn't intended to be an SQL replacement. There are things it intentionally doesn't do (although your problem isn't one of those) and the ORM is designed to make working with the Python models look "Pythonic", not to provide a Pythonic way to write SQL. If you're ever in a position to need a particular piece of SQL, the solution is to use SQL. Regards, Malcolm --~--~-~--~~~---~--~~ 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: Simple Query?
Thanks Karen, models are as follows... class MediaAndContainer(models.Model): media = models.ForeignKey(MediaLocal) order = models.FloatField(null=True, blank=True) ... class MediaLocal(models.Model): name = models.CharField(max_length=255, blank=True) height = models.IntegerField(null=True, editable=False) width = models.IntegerField(null=True, editable=False) ... I'm trying to get everything from the MediaLocal model and the 'order' field from the MediaAndContainer model... On Apr 12, 8:00 pm, Karen Traceywrote: > On Sun, Apr 12, 2009 at 5:06 PM, jrs_66 wrote: > > > Hi, > > > I'm new to django, but not new to SQL. I have a (seemingly) trivial > > query to run. In SQL it looks like- > > > SELECT media.*, media_and_containers.order > > FROM media > > INNER JOIN media_and_containers ON > > media.id = media_and_containers.media_id > > WHERE media.id = 1 > > > In the django ORM I think it should be- > > > media = MediaLocal.objects.select_related('order').filter( > > mediaandcontainer__media__exact = 1 > > ) > > > Yet, it seems, media.order does not exist... > > > What am I missing? > > You would likely get better responses if you posted the model definitions > you are using here. Your question as it stands requires anyone who might > want to help to reverse-engineer what your models maybe look like, and that > is both error prone and a bit more work than many people will want to go > through to help someone out. If the models are large with many fields, do > cut it down to essentials, but it would be helpful to see how you have > defined the relationship between these tables. > > > On a broader level, is Django's ORM intended for people who don't know > > how to write SQL? It seems that many hoops have to be jumped through > > to get basic SQL results... > > Django's ORM is intended to make it easy to access and manipulate your > relational data via Python objects. In-depth knowledge of SQL is not > necessary to use it, but nor should such knowledge hurt. If you have such > knowledge, it may help if you try to think of what you are trying to do in > terms of the Python models and not jump straight to the SQL you would use if > you were coding it directly in SQL. > > Karen --~--~-~--~~~---~--~~ 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: Send validation error message to the screen
Thanks Malcolm, What I'm looking after is sending my custom validation error message that is not covered by django. Thank you very much On Apr 13, 10:15 am, Malcolm Tredinnickwrote: > On Sun, 2009-04-12 at 23:37 +1000, Joshua Partogi wrote: > > Dear all, > > > I want to send and display validation error message from the view to > > the template, how do I do this in Django? I tried searching on the > > documents but could not find any topics on error message. Could anyone > > give me a hint on how to do this? > > Do you mean validation errors that are generated by a form when calling > is_valid()? If so, this happens automatically when the form is > redisplayed: > > def my_view(request, ...): > if request.method == "POST": > form = MyForm(request.POST) > if form.is_valid(): > ... > else: > # The "GET" path > form = MyForm() > ctxt = { > "form": form, > ... > } > return render_to_response("my_template.html", ctxt) > > In this sort of path, if an error occurs in the form, the form object > passed back to the template is the version with the data populated and > errors in place. So when the template displays the form, it will no > longer be an empty form (like it was the first time), but a form with > the initial submission filled in and error messages available. > > This is documented ([1]) but it's not necessarily the easiest thing to > find at the moment. > > [1]http://docs.djangoproject.com/en/dev/ref/forms/api/#how-errors-are-di... > > Is that what you were after? > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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: Mulitple Time Zone support?
On Sun, Apr 12, 2009 at 8:15 PM, ydjangowrote: > > What is the best way to provide multiple Time zone support? > > The registered user visiting the website should see all times and > dates as per his/her time zone and not as per time zone in > settings.py? > > We will keep user's time zone in our database. Dates and times will be > stored in Mysql DB and I think by default will be in Time zone of > Settings.py > > (Also where can I get list of all time zones to populate the select > dropdown.) > > I am sure like pretty much everything else Django has a easy solution > to it. > > > Take a look at django-timezones: http://code.google.com/p/django-timezones/which uses the pytz module for this. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: Does Django use persistent DB connection?
On Sun, 2009-04-12 at 06:39 -0700, Continuation wrote: > I can't find any info on that in the doc. > > Does that mean DB connections are not reused? If so, why? Seeing how > establishing DB connection is a pretty expensive operation I'd think > it makes sense to reuse them. One connection per request and then it's closed. > > Any way to have persistent connection with Django? Managing database connections in any advanced manner is quite complex and definitely out of scope for Django, because there are better tools. Django is a "shared nothing" (well, as close as possible) architecture, which means there is no requirement or dependency on anything have a lifecycle beyond a single request/response. If you want persistent connections, there are appropriate database-specific tools for making that happen transparently. For example, pgpool2 for PostgreSQL -- Django opens a connection to it (it behaves like a database server from an API perspective) and it manages the connections to the remote server. Regards, Malcolm --~--~-~--~~~---~--~~ 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: Send validation error message to the screen
On Sun, 2009-04-12 at 23:37 +1000, Joshua Partogi wrote: > Dear all, > > I want to send and display validation error message from the view to > the template, how do I do this in Django? I tried searching on the > documents but could not find any topics on error message. Could anyone > give me a hint on how to do this? Do you mean validation errors that are generated by a form when calling is_valid()? If so, this happens automatically when the form is redisplayed: def my_view(request, ...): if request.method == "POST": form = MyForm(request.POST) if form.is_valid(): ... else: # The "GET" path form = MyForm() ctxt = { "form": form, ... } return render_to_response("my_template.html", ctxt) In this sort of path, if an error occurs in the form, the form object passed back to the template is the version with the data populated and errors in place. So when the template displays the form, it will no longer be an empty form (like it was the first time), but a form with the initial submission filled in and error messages available. This is documented ([1]) but it's not necessarily the easiest thing to find at the moment. [1] http://docs.djangoproject.com/en/dev/ref/forms/api/#how-errors-are-displayed Is that what you were after? Regards, Malcolm --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Mulitple Time Zone support?
What is the best way to provide multiple Time zone support? The registered user visiting the website should see all times and dates as per his/her time zone and not as per time zone in settings.py? We will keep user's time zone in our database. Dates and times will be stored in Mysql DB and I think by default will be in Time zone of Settings.py (Also where can I get list of all time zones to populate the select dropdown.) I am sure like pretty much everything else Django has a easy solution to 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Simple Query?
On Sun, Apr 12, 2009 at 5:06 PM, jrs_66wrote: > > Hi, > > I'm new to django, but not new to SQL. I have a (seemingly) trivial > query to run. In SQL it looks like- > > SELECT media.*, media_and_containers.order > FROM media > INNER JOIN media_and_containers ON >media.id = media_and_containers.media_id > WHERE media.id = 1 > > In the django ORM I think it should be- > > media = MediaLocal.objects.select_related('order').filter( >mediaandcontainer__media__exact = 1 >) > > Yet, it seems, media.order does not exist... > > What am I missing? > You would likely get better responses if you posted the model definitions you are using here. Your question as it stands requires anyone who might want to help to reverse-engineer what your models maybe look like, and that is both error prone and a bit more work than many people will want to go through to help someone out. If the models are large with many fields, do cut it down to essentials, but it would be helpful to see how you have defined the relationship between these tables. > On a broader level, is Django's ORM intended for people who don't know > how to write SQL? It seems that many hoops have to be jumped through > to get basic SQL results... > Django's ORM is intended to make it easy to access and manipulate your relational data via Python objects. In-depth knowledge of SQL is not necessary to use it, but nor should such knowledge hurt. If you have such knowledge, it may help if you try to think of what you are trying to do in terms of the Python models and not jump straight to the SQL you would use if you were coding it directly in SQL. Karen --~--~-~--~~~---~--~~ 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: Strange issue with session not being saved
On Apr 13, 9:43 am, Julien Phalipwrote: > Hi, > > I've implemented and ajax upload progress bar and I've got a strange > issue with sessions. I've reused the exact same code from another > project where it works perfectly, so I assume there is some kind of > configuration problem. Any hint on how to debug this would be very > welcome. > > Basically, the way it works is that a custom upload handler updates a > session entry with the progress of the upload as new chunks of a big > file are received. In parallel, an ajax request is periodically sent > to fetch the session entry and update the progress bar in the > frontend. > > However, the problem is that the session entry is not saved until the > file has finished being uploaded. Whenever the ajax requests are sent > the new session entry is not accessible at all. It doesn't seem to be > saved. > > I've tried to set the "SESSION_SAVE_EVERY_REQUEST = False" setting, > and I also tried to set "request.session.modified = True" right before > saving the session entry. But that didn't make a difference. Both the > upload and ajax requests use the same domain. Both projects (the one > that works and the one that doesn't) use MySQL. > > Could that be a problem in Django's or Apache configurations? Hello again, My colleague has found something interesting in the error logs on the server: 2009/04/12 01:21:19 [warn] 23290#0: *101972 a client request body is buffered to a temporary file /usr/local/nginx/client_body_temp/ 05, client: 115.64.36.192, server: my.domain.com, request: "POST /tester/?X-Progress-ID=1914b38e-272a-11de-92cd-00221924bc8a HTTP/ 1.1", host: "my.domain.com", referrer: "http://my.domain.com/tester/; It seems like Nginx is messing things up. (BTW, Nginx is not set up on the server of the project that works, but it is set up on the project that doesn't work). Does it mean that Nginx, as it is currently configured, may prevent multiple POST requests to be processed at the same time? Thanks a lot! Julien --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Strange issue with session not being saved
Hi, I've implemented and ajax upload progress bar and I've got a strange issue with sessions. I've reused the exact same code from another project where it works perfectly, so I assume there is some kind of configuration problem. Any hint on how to debug this would be very welcome. Basically, the way it works is that a custom upload handler updates a session entry with the progress of the upload as new chunks of a big file are received. In parallel, an ajax request is periodically sent to fetch the session entry and update the progress bar in the frontend. However, the problem is that the session entry is not saved until the file has finished being uploaded. Whenever the ajax requests are sent the new session entry is not accessible at all. It doesn't seem to be saved. I've tried to set the "SESSION_SAVE_EVERY_REQUEST = False" setting, and I also tried to set "request.session.modified = True" right before saving the session entry. But that didn't make a difference. Both the upload and ajax requests use the same domain. Both projects (the one that works and the one that doesn't) use MySQL. Could that be a problem in Django's or Apache configurations? Any help would be much appreciated :) Thanks! Julien --~--~-~--~~~---~--~~ 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: Simple Query?
Thanks for the tip, however, it doesn't really help me out. I've read the docs, repeatedly, my problem is that I can't seem to get data from a related table (see my question above). Thanks On Apr 12, 7:00 pm, Ovnicraftwrote: > 2009/4/12 jrs_66 > > > > > > > Hi, > > > I'm new to django, but not new to SQL. I have a (seemingly) trivial > > query to run. In SQL it looks like- > > > SELECT media.*, media_and_containers.order > > FROM media > > INNER JOIN media_and_containers ON > > media.id = media_and_containers.media_id > > WHERE media.id = 1 > > > In the django ORM I think it should be- > > > media = MediaLocal.objects.select_related('order').filter( > > mediaandcontainer__media__exact = 1 > > ) > > > Yet, it seems, media.order does not exist... > > > What am I missing? > > > On a broader level, is Django's ORM intended for people who don't know > > how to write SQL? It seems that many hoops have to be jumped through > > to get basic SQL results... > > remember MVC, so That is not just for dont write SQL, it is to make the code > more clean and no has mixed lang and many reasons you can find, but if you > need write SQL would be better if you read the documentation. > > http://docs.djangoproject.com/en/dev/topics/db/queries/ > > > > > Thanks, > > > jim > > -- > Cristian Salamea > CEO GnuThink Software Labs > Software Libre / Open Source > (+593-8) 4-36-44-48 --~--~-~--~~~---~--~~ 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: Simple Query?
2009/4/12 jrs_66> > Hi, > > I'm new to django, but not new to SQL. I have a (seemingly) trivial > query to run. In SQL it looks like- > > SELECT media.*, media_and_containers.order > FROM media > INNER JOIN media_and_containers ON >media.id = media_and_containers.media_id > WHERE media.id = 1 > > In the django ORM I think it should be- > > media = MediaLocal.objects.select_related('order').filter( >mediaandcontainer__media__exact = 1 >) > > Yet, it seems, media.order does not exist... > > What am I missing? > > On a broader level, is Django's ORM intended for people who don't know > how to write SQL? It seems that many hoops have to be jumped through > to get basic SQL results... remember MVC, so That is not just for dont write SQL, it is to make the code more clean and no has mixed lang and many reasons you can find, but if you need write SQL would be better if you read the documentation. http://docs.djangoproject.com/en/dev/topics/db/queries/ > > > Thanks, > > jim > > > -- Cristian Salamea CEO GnuThink Software Labs Software Libre / Open Source (+593-8) 4-36-44-48 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Simple Query?
Hi, I'm new to django, but not new to SQL. I have a (seemingly) trivial query to run. In SQL it looks like- SELECT media.*, media_and_containers.order FROM media INNER JOIN media_and_containers ON media.id = media_and_containers.media_id WHERE media.id = 1 In the django ORM I think it should be- media = MediaLocal.objects.select_related('order').filter( mediaandcontainer__media__exact = 1 ) Yet, it seems, media.order does not exist... What am I missing? On a broader level, is Django's ORM intended for people who don't know how to write SQL? It seems that many hoops have to be jumped through to get basic SQL results... Thanks, 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-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: newbie question: django-registration
Eh, Never mind. Something is wrong with my root url (fixing the link from the email activated the account). I will fix it. On Sun, Apr 12, 2009 at 12:21 PM, MrBodjangleswrote: > Hi Folks and Happy Easter! > > OK, making slow but sure progress on learning Django. > > I am using django-registration, have provided the simple templates > required, and am to the point that a user can register (their usename, > password, etc. get populated in the auth_user table of the PostgreSQL > databae I am using), and receives an email. > > I am stuck on the activation. > > When I check my email and click on the link, I receive the following: > "The requested URL /accounts/activate/ > 637cd08106eea9b1139efd34a0fa79a5d7f90494/ was not found on this > server" > > I had assumed that the /accounts/activate/ folder > would have been automatically generated? > > I added this line to my URLConf, thinking this was the reason: >(r'^accounts/activate// > $','registration.views.activate'), > > What step am I missing? > > Advanced 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: Question about administration
On Apr 12, 8:16 am, Karlwwrote: > Hey all, > > I had a general question about administration in Django. So I do not > think my situation is unique, so I don't want to go out and make a > customer solution if there is already something out there. > > What i would like to have happen would be to separate my site into > "working areas", and each working area only has the ability to > interact with other items in their area. This would keep a user in > area 1 from interacting with a user in area 2, and furthermore admins > from doing the same. > > A way that I know how to do this would be to roll out a new django > project for each "working area". But have the "working area" solution > that i have in my head seems to be a bit more elegant. You would > update the views/models on 1 project instead of having to script a > deployment across several. > > Is there some django app that already has this built in? Any info > would be helpful. > > Best Regards, > > Karlw If I understood you correctly, you just want to restrict areas of a website, such as apps or certain models. If that's the case, check out the following snippet: http://www.djangosnippets.org/snippets/334/ If that doesn't tickle your fancy, check out the following: http://docs.djangoproject.com/en/dev/topics/auth/#permissions and http://docs.djangoproject.com/en/dev/ref/models/options/#permissions --~--~-~--~~~---~--~~ 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 question: django-registration
Hi Folks and Happy Easter! OK, making slow but sure progress on learning Django. I am using django-registration, have provided the simple templates required, and am to the point that a user can register (their usename, password, etc. get populated in the auth_user table of the PostgreSQL databae I am using), and receives an email. I am stuck on the activation. When I check my email and click on the link, I receive the following: "The requested URL /accounts/activate/ 637cd08106eea9b1139efd34a0fa79a5d7f90494/ was not found on this server" I had assumed that the /accounts/activate/ folder would have been automatically generated? I added this line to my URLConf, thinking this was the reason: (r'^accounts/activate// $','registration.views.activate'), What step am I missing? Advanced 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: Question about administration
The main difference between "working areas" and the sites framework is that I would like to have a single login page. Also, this might be my lack of understanding of the site framework, but it seems that it's main focus is for separate domains to share information. The "work area" idea that I shared below restricts users for sharing information that exists in the same domain/site. The best example that I was able to stumble across is detailed in the following link: http://www.hoboes.com/Mimsy/?ART=621 They say something along the lines "We’ll need to create our own access limits on a per-record basis". I guess if there is no easy answer, I just need to try to hack this out as best I can. Thanks a lot for the feedback and I plan on staying subscribed to this mailing list, maybe I can jump on the questions that have the easy answers. -Karlw On Apr 12, 2009, at 2:17 PM, Andy Leiwrote: > > http://docs.djangoproject.com/en/dev/ref/contrib/sites/#ref-contrib-sites > > is this what you're looking for? > > > On Apr 12, 10:16 am, Karlw wrote: >> Hey all, >> >> I had a general question about administration in Django. So I do not >> think my situation is unique, so I don't want to go out and make a >> customer solution if there is already something out there. >> >> What i would like to have happen would be to separate my site into >> "working areas", and each working area only has the ability to >> interact with other items in their area. This would keep a user in >> area 1 from interacting with a user in area 2, and furthermore admins >> from doing the same. >> >> A way that I know how to do this would be to roll out a new django >> project for each "working area". But have the "working area" >> solution >> that i have in my head seems to be a bit more elegant. You would >> update the views/models on 1 project instead of having to script a >> deployment across several. >> >> Is there some django app that already has this built in? Any info >> would be helpful. >> >> Best Regards, >> >> Karlw > > --~--~-~--~~~---~--~~ 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: deletion of "distant" related objects
> For a model such as Book, you could iterate through > Book._meta.get_all_field_names(), call Book._meta.get_field_by_name() > for each name and look at the "direct" component of the returned result > to see which are the reverse relations. Those are then the things > pointing to your model. > > There are docstrings on get_field_by_name() and get_all_field_names() in > django/db/models/options.py that will help you out there. > Great, this was very helpful. > > One other thought - let me know if you see any issue with this. Let's > > say I just never want my reader objects to get deleted based on > > related object deletions. I think I can just define > > > class Reader: > > def delete(self): > > pass > > > Then delete will do nothing and if I really want to delete my reader I > > can call some other method that I define that then calls super(Reader, > > self).delete(). > > That will work for a direct call. Isn't there going to be some related > object deletion cases that still won't be caught, though? Isn't this > exactly the case that you were examining in the initial post? Yes, of course you are right. I still hadn't fully grocked that delete () never get called in this case. I get that now. > Ultimately, Python is a language for consenting adults. If you don't > want the object to be deleted, don't call delete on things involving > that object. > Well, that seems a little heavy handed. I mean, when trying to create db driven web app, I think it is important to allow the users to delete the objects and not have bad side effects. That said, I understand that django is a developer's tool and there is always a workaround that a developer can come up with. I found one that works fine for my particular app. > It's understood that delete behaviour is something that has a few > different options. Coming up with a save API for controlling those which > doesn't leak SQL-juice all over the Python level code or make things > horribly an untenably inefficient, has been something we've been > wrestling with for quite a while. So far without really having a great > solution that we're happy committing. This isn't for want of actual hard > thinking on the problem by a number of people. > > For now, it's a matter of being careful and trusting your users to not > do crazy stuff. > > It's not optimal, but it is survivable. yup, agreed it is a hard problem. I appreciate that you guys no doubt have your hands full and am absolutely fine with dealing with it as is. Thanks for your pointers, they were very helpful and I've dug my self out of my hole. Margie --~--~-~--~~~---~--~~ 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: Question about administration
http://docs.djangoproject.com/en/dev/ref/contrib/sites/#ref-contrib-sites is this what you're looking for? On Apr 12, 10:16 am, Karlwwrote: > Hey all, > > I had a general question about administration in Django. So I do not > think my situation is unique, so I don't want to go out and make a > customer solution if there is already something out there. > > What i would like to have happen would be to separate my site into > "working areas", and each working area only has the ability to > interact with other items in their area. This would keep a user in > area 1 from interacting with a user in area 2, and furthermore admins > from doing the same. > > A way that I know how to do this would be to roll out a new django > project for each "working area". But have the "working area" solution > that i have in my head seems to be a bit more elegant. You would > update the views/models on 1 project instead of having to script a > deployment across several. > > Is there some django app that already has this built in? Any info > would be helpful. > > Best Regards, > > Karlw --~--~-~--~~~---~--~~ 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: Generic relations swamp
Admin for language: from kyss.front.models import lang from django.contrib import admin class FrontAdmin(admin.ModelAdmin): fieldsets = [ ('General info', {'fields': ['name', 'short', 'locale', 'encoding', 'url', 'fdef', 'bdef']}), ('SEO stuff', {'fields': ['title', 'metadesc', 'metakeyw', 'websitename', 'websiteslogan']}), ] admin.site.register(lang, FrontAdmin) Admin for poll and translations: from kyss.poll.models import Poll from kyss.poll.models import Question from kyss.poll.models import Choice from kyss.poll.models import Trans from kyss.front.models import lang from django.contrib import admin from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic class QuestionInline(admin.TabularInline): model = Question extra = 2 class ChoiceInline(admin.TabularInline): model = Choice extra = 4 class TranslationInline(generic.GenericTabularInline): model = Trans extra = len(lang.objects.all()) class TransAdmin(admin.ModelAdmin): list_display = ['id', 'name'] class QuestionAdmin(admin.ModelAdmin): inlines = [ TranslationInline ] class ChoiceAdmin(admin.ModelAdmin): inlines = [ TranslationInline ] class PollAdmin(admin.ModelAdmin): fieldsets = [ ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}), ('Is this poll active', {'fields': ['active'] }), ] inlines = [ TranslationInline ] admin.site.register(Poll, PollAdmin) admin.site.register(Question, QuestionAdmin) admin.site.register(Choice, ChoiceAdmin) admin.site.register(Trans, TransAdmin) Models have not been changed. Alan. On Apr 12, 4:27 pm, matehatwrote: > Hi, > > can you show us the code for each of your admin classes? This probably > has something to do with some method overrides, but I can't say much > about the cause of your problem from the error message you gave... > > Cheers > > Mathieu --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Fwd: Default ManyToMany ordering
hi guys, let's say i have a ManyToMany relationship with an intermediary model; something like this: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(Person, through='Membership') class Membership(models.Model): person = models.ForeignKey(Person) group = models.ForeignKey(Group) order = models.IntegerField() how do i set it up so that when i query Persons belonging to Groups, it returns results in order? so that, if I have g = Group.objects.get(pk=1) then, the line g.members.all() should return the members sorted by order. I tried adding class Meta: ordering = ('order',) into the Membership class, but it's not working. the reason i need this is that i have an admin interface for Groups, but the members are getting found in the wrong order, which messes things up in the field. thanks in advance for your help! -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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Templates in models and i18n.
It's not an entire template, I'm just using the template system as an alternative to string formatting because of its name resolution capabilities. I found out how to do it, actually, I used ugettext instead of lazy an it works well! Poromenos On 12 Απρ 2009, at 19:52, Karen Traceywrote: > On Sun, Apr 12, 2009 at 11:29 AM, Poromenos > wrote: > > Hello, > I am trying to render a template in my models (to get the model > details in a printable format), but I want the template string to be > internationalised. ugettext_lazy does not return a string object, and > the template returns nothing. My code is: > > template = Template(_("{{ self.name }}")) > context = Context({"self": self}).render > return template.render(context) > > This fails. Is there something I can do , or do I have to forget about > internationalisation? Can I just use ugettext() instead? > > Have you read: http://docs.djangoproject.com/en/dev/topics/i18n/ > > particularly: > http://docs.djangoproject.com/en/dev/topics/i18n/#in-template-code > > ? > > You don't want to be translating an entire template, you want to > translate individual bits within the template. Consider that in > general a template will be filled with html tags, template > constructs (such as the {{ }} you have in yours), and such that it > makes no sense to translate. > > Karen > > > --~--~-~--~~~---~--~~ 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: Templates in models and i18n.
On Sun, Apr 12, 2009 at 11:29 AM, Poromenoswrote: > > Hello, > I am trying to render a template in my models (to get the model > details in a printable format), but I want the template string to be > internationalised. ugettext_lazy does not return a string object, and > the template returns nothing. My code is: > > template = Template(_("{{ self.name }}")) > context = Context({"self": self}).render > return template.render(context) > > This fails. Is there something I can do , or do I have to forget about > internationalisation? Can I just use ugettext() instead? Have you read: http://docs.djangoproject.com/en/dev/topics/i18n/ particularly: http://docs.djangoproject.com/en/dev/topics/i18n/#in-template-code ? You don't want to be translating an entire template, you want to translate individual bits within the template. Consider that in general a template will be filled with html tags, template constructs (such as the {{ }} you have in yours), and such that it makes no sense to translate. Karen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
doctest testing with templatefilters
hello, I am testing some of my filters with doctests. it's very easy, but I have to call the module with the filters manually: python /foo/bar/templatetags/eggs_extra.py -v to let the doctest run. Now I've added at the end of the egg.py the following code: def run_doctest(): import doctest doctest.testmod() and at the beginning of the tests.py the following: from foo/bar/templatetags/eggs_extra.py import run_doctest run_doctest() but nothing happens. what can I do that that the doctests in the template filters are run with ./manage.py test? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Templates in models and i18n.
Hello, I am trying to render a template in my models (to get the model details in a printable format), but I want the template string to be internationalised. ugettext_lazy does not return a string object, and the template returns nothing. My code is: template = Template(_("{{ self.name }}")) context = Context({"self": self}).render return template.render(context) This fails. Is there something I can do , or do I have to forget about internationalisation? Can I just use ugettext() 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-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 -~--~~~~--~~--~--~---
Question about administration
Hey all, I had a general question about administration in Django. So I do not think my situation is unique, so I don't want to go out and make a customer solution if there is already something out there. What i would like to have happen would be to separate my site into "working areas", and each working area only has the ability to interact with other items in their area. This would keep a user in area 1 from interacting with a user in area 2, and furthermore admins from doing the same. A way that I know how to do this would be to roll out a new django project for each "working area". But have the "working area" solution that i have in my head seems to be a bit more elegant. You would update the views/models on 1 project instead of having to script a deployment across several. Is there some django app that already has this built in? Any info would be helpful. Best Regards, Karlw --~--~-~--~~~---~--~~ 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: Generic relations swamp
Hi, can you show us the code for each of your admin classes? This probably has something to do with some method overrides, but I can't say much about the cause of your problem from the error message you gave... Cheers Mathieu --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Send validation error message to the screen
Dear all, I want to send and display validation error message from the view to the template, how do I do this in Django? I tried searching on the documents but could not find any topics on error message. Could anyone give me a hint on how to do this? Thank you very much -- If you can't believe in God the chances are your God is too small. Read my blog: http://joshuajava.wordpress.com/ Follow us on twitter: http://twitter.com/scrum8 --~--~-~--~~~---~--~~ 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: UnpickleableError when sessions are saved
As Alex pointed out, only picklable data can be put in the session. If you really need that ImagingCore object in the session, you have to make it somehow picklable by adding "__getstate__" and "__setstate__" method for picklability (see http://docs.python.org/library/pickle.html). Basically, you'd need to find out what data identifies the object as it is now (the image path for example) so that it can be constructed back from scratch into its current state from that data alone, which must in turn by picklable. Of course if the ImagingCore class is not one of your own, you'll have to inspect then subclass 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Does Django use persistent DB connection?
I can't find any info on that in the doc. Does that mean DB connections are not reused? If so, why? Seeing how establishing DB connection is a pretty expensive operation I'd think it makes sense to reuse them. Any way to have persistent connection 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-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 -~--~~~~--~~--~--~---
usage of Django in Atlanta?
What companies do you know of that are using Django in the Atlanta area? Marcel Duffoo --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
how to copy django session to tomcat?
HI,every body,i have a need: my searching system is doing by lucene,so i use tomcat,but all the other parts are running under django+apache+mod_python.now one user already has logined successful,but when he uses searching system,my site tells him that he had not logined, I knows it is beacause the Apache and tomcat did not share sessions,so i want to copy seesion in apache to tomcat,how to do?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: SQL Between query in sqlite3
Thank you Alex On Apr 11, 11:47 am, Alex Gaynorwrote: > On Sat, Apr 11, 2009 at 2:44 AM, Kenneth Gonsalves > wrote: > > > > > On Saturday 11 April 2009 11:16:52 Nalini wrote: > > > select * from Table where dates BETWEEN '2009-01-01' AND '2009-01-31' > > > Can any one help me? > > > Model.objects.filter(mydate__gte='2009-01-01' > > ).filter(mydate__lte='2009-01-31') > > -- > > regards > > kg > >http://lawgon.livejournal.com > > You can also do mydate__range=(datetime_obj1, datetime_obj2). > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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: SQL Between query in sqlite3
Hi Kg, Thank you very much On Apr 11, 11:44 am, Kenneth Gonsalveswrote: > On Saturday 11 April 2009 11:16:52 Nalini wrote: > > > select * from Table where dates BETWEEN '2009-01-01' AND '2009-01-31' > > Can any one help me? > > Model.objects.filter(mydate__gte='2009-01-01' > ).filter(mydate__lte='2009-01-31') > -- > 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 -~--~~~~--~~--~--~---
Re: deletion of "distant" related objects
On Sun, 2009-04-12 at 00:40 -0700, Margie wrote: [...] > Let's say that my Publisher and Book classes are in one app, and that > app doesn't know anything about the readers. Is there any simple way > to find all related object fields that point to book and clear them > out, without having to know their names For a model such as Book, you could iterate through Book._meta.get_all_field_names(), call Book._meta.get_field_by_name() for each name and look at the "direct" component of the returned result to see which are the reverse relations. Those are then the things pointing to your model. There are docstrings on get_field_by_name() and get_all_field_names() in django/db/models/options.py that will help you out there. > ? > > One other thought - let me know if you see any issue with this. Let's > say I just never want my reader objects to get deleted based on > related object deletions. I think I can just define > > class Reader: > def delete(self): > pass > > Then delete will do nothing and if I really want to delete my reader I > can call some other method that I define that then calls super(Reader, > self).delete(). That will work for a direct call. Isn't there going to be some related object deletion cases that still won't be caught, though? Isn't this exactly the case that you were examining in the initial post? > The actual object that is my "reader" (the above example was used just > for simplicity) is really my UserProfile object. I would think that > this is a common problem Boy do I hate that phrase! For every possible programming problem, there is certainly a non-zero number of people who want some particular piece of behaviour. But there's pretty much no way to measure "common" unless you have a total userbase of, like, 17 people. At some point, everything is both common to some group and pretty much irrelevant to the majority. > - not wanting one's userProfiles to ever get > deleted. Ultimately, Python is a language for consenting adults. If you don't want the object to be deleted, don't call delete on things involving that object. It's understood that delete behaviour is something that has a few different options. Coming up with a save API for controlling those which doesn't leak SQL-juice all over the Python level code or make things horribly an untenably inefficient, has been something we've been wrestling with for quite a while. So far without really having a great solution that we're happy committing. This isn't for want of actual hard thinking on the problem by a number of people. For now, it's a matter of being careful and trusting your users to not do crazy stuff. It's not optimal, but it is survivable. Regards, Malcolm --~--~-~--~~~---~--~~ 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: deletion of "distant" related objects
I see. So then I think what you are saying is that if I want to avoid these "readers" getting deleted, prior to deleting my publisher I need to find all readers of the books publised by that publisher, and clear them out so that they are no longer readers of those books. Let's say that my Publisher and Book classes are in one app, and that app doesn't know anything about the readers. Is there any simple way to find all related object fields that point to book and clear them out, without having to know their names? One other thought - let me know if you see any issue with this. Let's say I just never want my reader objects to get deleted based on related object deletions. I think I can just define class Reader: def delete(self): pass Then delete will do nothing and if I really want to delete my reader I can call some other method that I define that then calls super(Reader, self).delete(). The actual object that is my "reader" (the above example was used just for simplicity) is really my UserProfile object. I would think that this is a common problem - not wanting one's userProfiles to ever get deleted. In my case my UserProfile contains a ForeignKey to a particular "Chip" object, identifying it as the "current chip" (ie, the one they want to be looking at). If that Chip gets deleted, I don't want my UserProfile to get deleted. As I write this, it occurs to me that another option would be to make the UserProfile contain a manytomany field that identifies the current chip (rather than a foreingKey). I think if I did that, I would not have this problem, right? Is there a down side to making it a ManyToMany field rather than a ForeignKey? It's misleading (since there can be only one current chip pointed at by the userprofile), but it seems to solve the problem. Margie On Apr 12, 12:06 am, Malcolm Tredinnickwrote: > On Sat, 2009-04-11 at 23:29 -0700, Margie wrote: > > I am having some trouble with the deletion of related objects that are > > multiple levels away from the object being deleted. I've read a bunch > > of stuff written on deletion of related objects, but nothing on this > > particular problem - hoping someone can help. > > > Say I have a model like this: > > > class Publisher(models.Model): > > name = models.CharField(max_length=100) > > > class Book(models.Model): > > publisher = models.ForeignKey(Publisher, blank=True, null=True) > > > class Reader(models.Model): > > book = models.ForeignKey(Book, blank=True, null=True) > > > When a publisher is deleted, I would its book_set to be deleted, and > > this happens by default. However, when a book is deleted, either by > > deleting the book explicitely or due to its related publisher being > > deleted, I don't want the book's reader_set to be deleted. In Book I > > have this: > > > class Book(models.Model): > > def delete(self): > > self.reader_set.clear() # make any readers of the book no longer > > reference the book to be deleted > > super(Book, self).delete() > > The basic problem you're up against here is that a model's delete() > method is not necessarily going to be run when it is deleted indirectly. > Django tries to optimise deletes and updates so that they are single (or > minimal numbers of) SQL queries, which means not calling a method on > each instance, but, rather, doing a bulk delete at the database level. > > This is documented, although it's one of those things that doesn't > immediately jump > out:http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-que... > > (The queryset and model documentation is a bit all over the place at the > moment -- we need a few more links between places.) > > I think that's really going to be the showstopper here. You can't hope > to control the bulk delete (which includes related object deletion) at > that sort of level. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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: deletion of "distant" related objects
On Sat, 2009-04-11 at 23:29 -0700, Margie wrote: > I am having some trouble with the deletion of related objects that are > multiple levels away from the object being deleted. I've read a bunch > of stuff written on deletion of related objects, but nothing on this > particular problem - hoping someone can help. > > Say I have a model like this: > > class Publisher(models.Model): > name = models.CharField(max_length=100) > > class Book(models.Model): > publisher = models.ForeignKey(Publisher, blank=True, null=True) > > class Reader(models.Model): > book = models.ForeignKey(Book, blank=True, null=True) > > When a publisher is deleted, I would its book_set to be deleted, and > this happens by default. However, when a book is deleted, either by > deleting the book explicitely or due to its related publisher being > deleted, I don't want the book's reader_set to be deleted. In Book I > have this: > > class Book(models.Model): > def delete(self): > self.reader_set.clear() # make any readers of the book no longer > reference the book to be deleted > super(Book, self).delete() The basic problem you're up against here is that a model's delete() method is not necessarily going to be run when it is deleted indirectly. Django tries to optimise deletes and updates so that they are single (or minimal numbers of) SQL queries, which means not calling a method on each instance, but, rather, doing a bulk delete at the database level. This is documented, although it's one of those things that doesn't immediately jump out: http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-queries-delete (The queryset and model documentation is a bit all over the place at the moment -- we need a few more links between places.) I think that's really going to be the showstopper here. You can't hope to control the bulk delete (which includes related object deletion) at that sort of level. Regards, Malcolm --~--~-~--~~~---~--~~ 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 find the version of Django?
On Sun, Apr 12, 2009 at 2:38 AM, ydjangowrote: > > How do I find which version of django I have on my server? > > > import django; print django.VERSION That should have a tuple with the version info. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to find the version of Django?
How do I find which version of django I have on my server? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
deletion of "distant" related objects
I am having some trouble with the deletion of related objects that are multiple levels away from the object being deleted. I've read a bunch of stuff written on deletion of related objects, but nothing on this particular problem - hoping someone can help. Say I have a model like this: class Publisher(models.Model): name = models.CharField(max_length=100) class Book(models.Model): publisher = models.ForeignKey(Publisher, blank=True, null=True) class Reader(models.Model): book = models.ForeignKey(Book, blank=True, null=True) When a publisher is deleted, I would its book_set to be deleted, and this happens by default. However, when a book is deleted, either by deleting the book explicitely or due to its related publisher being deleted, I don't want the book's reader_set to be deleted. In Book I have this: class Book(models.Model): def delete(self): self.reader_set.clear() # make any readers of the book no longer reference the book to be deleted super(Book, self).delete() This works if I explicitly delete a book (ie, by "works", I mean that the book's readers stay around). However, if I delete a publisher, it seems that during Model::delete(), when _collect_sub_objects() runs, it runs through all of the related objects finds the related books, and then runs through the books' related objects and find the related readers. It targets them for deletion and then at some point they get deleted. It seems to me (I don't fully grock this code, so I could be wrong here) that by the time my Book::delete() code runs, the readers of the book have already been targeted for deletion and the self.reader_set.clear() is not having the effect I want. So I'm trying to figure out how I should avoid the readers getting deleted in this case? Thanks for any insights! Margie --~--~-~--~~~---~--~~ 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: Help! PNG file upload error...
Thanks for your suggestion. But Python 2.5 already has zlib moudle. To png file,I wrote lines of code to save it first on disk and then handled the saved copy,then that works. I do not why there is some differencies between png file and file of other formats.The following is my code: parser = ImageFile.Parser() for chunk in f.chunks(): parser.feed(chunk) img = parser.close() if format == 'png': des_origin_f = open("tmp.png","ab") for chunk in f.chunks(): des_origin_f.write(chunk) des_origin_f.close() img = Image.open("tmp.png") ##other operations to handle the image img.save("test"+"."+fileExt) #save this image I can not make sure whether the problem is caused by Django. Because what my code tells is that PIL can handle the png file from a disk,but can not handle a png file from a Django response(you can see my code in the first message and compare with the code above). On Apr 10, 9:46 pm, Brian Nealwrote: > On Apr 9, 12:45 am, higer wrote: > > > When I upload a PNG file and usePILto handle it,there will be an > > error occured: > > 'NoneType' object is unsubscriptable > > > I do not know why and other formats(BMP GIF JPG JPEG) are all ok. > > I don't know if this is your problem, but in order to use certain file > formats inPILyou have to have some prequisites installed. Here is > thePILdoc page for PNG support: > > http://www.pythonware.com/library/pil/handbook/format-png.htm > > In particular, note: > > "PILidentifies, reads, and writes PNG files containing "1", "L", "P", > "RGB", or "RGBA" data. Interlaced files are currently not supported." > > And also: > > "Note: To enable PNG support, you need to build and install the ZLIB > compression library before building the Python Imaging Library. See > the distribution README for details." > > BN --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---