Re: track change
Google for Django Audit Log and/or Audit Trail. While some of the packages might not be under active development, they may be able to point you in the right direction. Cheers, AT -- Sent from my phone, please excuse any typos. -- On May 23, 2012 5:45 PM, "Carsten Jantzen" wrote: > Hi > > I am looking for a way to track a skill change for a player in a > online game. > > model: > Player 1 > skill_x=1 > skill_y=1 > > During next update I get a change > > Player 1 > skill_x=2 > skill_y=1 > > When I load the player I would like to see his latest stats. > If I goto the players page I would like to be able to view when and > what skill changed. > > I am looking for a good way to implement it. > I was thinking to make the skill it's own object and make a one to > many relation on the player. > What I am afraid of is that the same skill will show up multiple times > when loading the player. > > Hope to get some input. > > /Carsten > > -- > 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. > > -- 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: Registering and authenticating via iPhone/Android app
I read somewhere that Instagram use django-piston. But them some people are saying that Piston has had any development done in over a year. -m On 23 May 2012 23:12, Roarster wrote: > On Wednesday, 23 May 2012 13:02:15 UTC+1, bruno desthuilliers wrote: >> >> On May 23, 1:12 pm, Roarster wrote: >> > I'm developing a site using Django using the built in user >> authentication >> > module. This is all working fine and users can register, login, etc. >> on >> > the web site with no problems. The plan is to also have companion >> > iPhone/Android apps where users can register/login and then access >> their >> > data on the main site. This is where I'm a bit unsure of how to >> proceed. >> > I've been looking into using TastyPie to create a REST API which I >> think >> > will work fine for accessing/updating data but I'm not sure if this is >> > appropriate for creating new users and authenticating existing users. >> >> I'm definitly not an expert when it comes to mobile apps, but there >> are quite a few known REST (or XMLRPC or else) APIs around that >> include at least user authentication - think google (including >> youtube, blogger etc), dailymotion, most blogging platforms, etc. >> >> As far as I'm concerned, I'd definitly use the API for authentication >> too (possibly using OAuth). wrt/ registration, well, I have not >> checked if any of the above APIs support this, but from your Django >> app's POV, it's still all about HTTP requests / responses anyway so >> well... >> >> My 2 cents, really.. > > > Thanks Bruno. I've had a bit more of a look into this and everyone seems > to be using OAuth, as you mention. I did try to get this working with the > Tastypie API but I couldn't really find any documentation and found it a > bit of a struggle. I guess I'll have to look into this further. > > I've also looked into the public APIs you mention and none of them seem to > allow registration (at least not on the public API). I guess since my API > will be private (at least initially) I can do what I want, I was just > hoping to find out what some other well used apps (e.g. Instagram) might > use for communication. Do you think it's possible they just have another > REST API they don't disclose? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/68UDvibDrpAJ. > > 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. > -- 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 call RegexValidator explicitly?
Hi all, I see in docs.djangoproject.com/en/dev/ref/validators/ how to include validators in a form field, but I have a field that needs to be validated with a regular expression determined by another field. Please help me call RegexValidator explicitly the right way. For one thing, I don't see how to pass the field to the validator. For another, I'm not sure exactly what to test for to determine that validation failed. The code follows: from django import forms from django.core.validators import * class IdentForm(forms.Form): ident = forms.CharField() ident_type = forms.ChoiceField(choices=( ('EIN','Employer ID'), ('SSN','Social Security Number'), )) TYPE_CHOICES = ( ('EIN','\d{2}-\d{7}'), ('SSN','\d{3}-\d{2}-\d{4}'), ) def clean(self): cleaned_data = super(IdentForm, self).clean() ident = cleaned_data.get('ident') ident_type = cleaned_data.get('ident_type') regexp = TYPE_CHOICES[ident_type] RegexValidator([regexp]) # What's missing? # How do I pass ident to the validator? if ??: # Do I test for existence of error message? ident = '' return cleaned_data What errors do I have? 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: Django site updater
I use buildbot to export the code from svn whenever I commit to trunk. It also performs other related tasks such as deleting the entire site first then running tests, compiling to .pyc, deleting source, chowning and chmoding etc. I really like buildbot because you can add programmed (in Python) steps to do anything you like. On 24/05/2012 4:36am, Alexis Bellido wrote: I use Fabric to automate as much as possible, not only for production but also for my development and staging environments. I have shared some code in github: https://github.com/alexisbellido/The-Django-gunicorn-fabfile-project I'm currently finishing some changes for making this code more flexible and working with Django 1.4, where the project's directory layout has changed a bit. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/VNxGjGEVV90J. 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. -- 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 object permission approach
Hey, I think it really depends on how much complexity you want. We use a package called userena which depends upon Guardian. All that I know about Guardian is it's no fun when schema migrations get messed up :) In all honestly, though, I should have probably read more about it before using an application that depends upon it. What we do is simply override the querysets. It wouldn't be very difficult to subclass some of the Class Based Views to make this easier on you. For example: def get_queryset(self, queryset=None): # Not sure if that should be qs -- I'd have to look at the source qs = queryset.filter(user = self.request.user) return qs In other places where I am using ModelForms and letting users update their own objects, I just override get_object like you mentioned. On Wed, May 23, 2012 at 4:53 PM, Paul wrote: > Assume i have a model as follows: > > class Website(models.Model): > user = models.ForeignKey(User) > name = models.CharField(unique=True, max_length=32) > url = models.URLField(unique=True) > > Now i have a generic (detail) view as follows: > > class WebsiteRead(DetailView): > model = Website > > @method_decorator(login_required()) > def dispatch(self, *args, **kwargs): > return super(WebsiteRead, self).dispatch(*args, **kwargs) > > I want users to only be able to view an object when they have created > it; [self.request.user == Website.user]. > > What is the best approach to create this? > - I could overload get_object to query for the object based on the pk > and the fk of the user. > - Or should i use a package (from > http://www.djangopackages.com/grids/g/perms/) > such as django-guardian? > > Paul > > -- > 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. > -- 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.
model form_set can not delete
Hi there, i have a problem whereby, if i for form in formset line by line and run form.save(). my delete (ticked) item will not be deleted. and if i 'm direct using formset.save(). it did deleted. where am i code wrong already? q1 = modelformset_factory(CustomerDetail, form= CustomerDetail lForm, can_delete=True) # bla bla bla if request.method == 'POST': find_formsetcustomerdetail = CustomerDetail .objects.filter(customerheader__id=id_unquekey) formset = q1(request.POST,request.FILES,queryset=find_formsetcustomerdetail) if formset.is_valid(): for formline in formset: # do checking..bla bla bla formline.save() Regards, MH -- 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 object permission approach
Assume i have a model as follows: class Website(models.Model): user = models.ForeignKey(User) name = models.CharField(unique=True, max_length=32) url = models.URLField(unique=True) Now i have a generic (detail) view as follows: class WebsiteRead(DetailView): model = Website @method_decorator(login_required()) def dispatch(self, *args, **kwargs): return super(WebsiteRead, self).dispatch(*args, **kwargs) I want users to only be able to view an object when they have created it; [self.request.user == Website.user]. What is the best approach to create this? - I could overload get_object to query for the object based on the pk and the fk of the user. - Or should i use a package (from http://www.djangopackages.com/grids/g/perms/) such as django-guardian? Paul -- 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.
track change
Hi I am looking for a way to track a skill change for a player in a online game. model: Player 1 skill_x=1 skill_y=1 During next update I get a change Player 1 skill_x=2 skill_y=1 When I load the player I would like to see his latest stats. If I goto the players page I would like to be able to view when and what skill changed. I am looking for a good way to implement it. I was thinking to make the skill it's own object and make a one to many relation on the player. What I am afraid of is that the same skill will show up multiple times when loading the player. Hope to get some input. /Carsten -- 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.
derived fields and getattr
I was asked to make a mod to a large django app that I didn't write. They wanted me to add a derived field to a query, e.g. select col1-col2 from table ... I did that and it works, but in some other part of the code it calls getattr(object, field) and when field == col1-col2 it blows up with"object has no attribute 'col1-col2'" Is there some way I can make getattr work for the derived field? TIA! -larry -- 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: ordering m2m query based on through table
On May 23, 3:36 pm, akaariai wrote: > I guess (again!) that the reason for the LEFT JOIN is this call in sql/ > compiler.py:_setup_joins() > > self.query.promote_alias_chain(joins, > self.query.alias_map[joins[0]].join_type == self.query.LOUTER) > > This seems to promote the join to outer join too aggressively, the > promote_alias_chain call does not see that the join is constrained by > other conditions already. I don't know if this has any practical > effects, nor do I know how easy/hard this would be to fix. It could be > as easy as just starting from the first new join generated by the > _setup_joins() call, and leaving the pre-existing joins alone. If it > is that easy, it should be fixed... I have a fix for the issue mentioned above. I haven't figured out how to create a query where promotion from INNER JOIN to LEFT OUTER JOIN will cause wrong results. Fixing this is still worth it, as even if there isn't a query where the current promotion logic breaks the results, it is possible there one day will be a way to do that. There might be performance impacts at least for some databases. If somebody happens to figure out a query which produces wrong results due to the INNER -> OUTER promotion it would be good to add a test case for that. See this pull request for details: https://github.com/django/django/pull/90 - Anssi -- 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 views create_object and prefill form data?
For the record, you could go even further (and you may already have), and make the get_initial part of a WebsiteMixin so that you can reuse it in other views without having to repeat yourself. Cheers, AT -- Forwarded message -- From: Paul Date: Wed, May 23, 2012 at 5:09 PM Subject: Re: Generic views create_object and prefill form data? To: Django users Solved it by migrating to the class based generic views, then fed initial form data to the constructor of the form by overloading get_initial on the view class. Paul -- 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. -- 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 views create_object and prefill form data?
Solved it by migrating to the class based generic views, then fed initial form data to the constructor of the form by overloading get_initial on the view class. Paul -- 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: Django site updater
I use Fabric to automate as much as possible, not only for production but also for my development and staging environments. I have shared some code in github: https://github.com/alexisbellido/The-Django-gunicorn-fabfile-project I'm currently finishing some changes for making this code more flexible and working with Django 1.4, where the project's directory layout has changed a bit. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/VNxGjGEVV90J. 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: JQuery .get new url is not updating the page
Thanks Kurtis, *1. Get your dynamic page via AJAX with some given query* Here is work flow, a: when user clicks on "Result" button on the main menu, the table is displayed in which first column is "IDs". and url becomes http://127.0.0.1:8080/Home/Search/ b: when user clicks on any of the "IDs" on the table id results is displayed and url becomes http://127.0.0.1:8080/Home/Search/#RunId_TestCases%3FClickedRunId%3D*Thu- May-17-11%253A32%253A21-2012 *Here is what I am using Jquery $.get("RunId_TestCases",{ClickedRunId:ClickedRunId},function(data){ window.location.hash = encodeURIComponent(this.url); ShwowTable(data[results]); }); Url is getting changed with contents changed but, that changed url can not be used again to get the same content. *2:Modify the URL to match the query* * I think, this step is missing . To do this step, should I parse the new url and read id and run $.get function again? Regards, * On Wed, May 23, 2012 at 12:54 PM, Kurtis Mullins wrote: > I'm not sure of the use-case on this but you could possibly take the > following approach: > > 1. Get your dynamic page via AJAX with some given query > 2. Modify the URL to match the query > 3. When a user accesses the same page with the given query > (my/page/?foo=bar) then they'll see the same thing > > Of course this will probably require modifying your view to accept queries. > > On Wed, May 23, 2012 at 11:23 AM, Furqan Malik > wrote: > > Thank you so much Lee, > > > > I am able to change the url but when i copy and past that url to new > > browser, it opens parent page. > > > > Any help? > > > > > > On Sat, May 19, 2012 at 10:49 AM, Lee Hinde wrote: > >> > >> > >> On May 18, 2012, at 8:24 PM, Furqan Malik wrote: > >> > >> Thanks for the reply, > >> > >> You misunderstood my question. > >> > >> Passed_TestCases = data['Data1']; > >> Failed_TestCases = data['Data2']; > >> These values are fine, I am using them to create the table. > >> > >> My question is once these values come from view.py, I want to change the > >> browser url so that url can be send to others. > >> > >> > >> You're right, I did. > >> > >> > >> > http://stackoverflow.com/questions/136458/change-the-url-in-the-browser-without-loading-the-new-page-using-javascript > >> > >> > >> > >> On Fri, May 18, 2012 at 3:52 PM, Lee Hinde wrote: > >>> > >>> > >>> On May 18, 2012, at 11:52 AM, furqanmlk wrote: > >>> > >>> Hi there, > >>> > >>> I implemented the JQuery to get the data from Database server and > display > >>> in the form of table on the page when user click one of the DOM > element. > >>> I tried , > >>> > >>> JQuery Code: > >>> $.get("RunId_TestCases",{Variable:Value},function(data){ > >>> > >>> > >>> Passed_TestCases = data['Data1']; > >>> Failed_TestCases = data['Data2']; > >>> //window.location.hash = this.url > >>>//window.location.assign(this.url) > >>> > >>> > >>> > >>> not knowing anything about the page, but you want something more like: > >>> > >>> $("#ID_FOR_THE_FIELD").val(data['Data1']); > >>> > >>> > >>> using window.location browser url gets changed but page goes to empty > >>> page with data values. > >>> > >>> > >>> Can you please help to solve this issue. > >>> > >>> > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "Django users" group. > >> To post to this group, send email to django-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. > > > > > > -- > > 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. > > -- > 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. > > -- 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: JQuery .get new url is not updating the page
Thanks Kurtis, 1. Get your dynamic page via AJAX with some given query Here is work flow, a: when user clicks on "Result" button on the main menu, the table is displayed in which first column is "IDs". and url becomes http://127.0.0.1:8080/Home/Search/ On Wed, May 23, 2012 at 12:54 PM, Kurtis Mullins wrote: > I'm not sure of the use-case on this but you could possibly take the > following approach: > > 1. Get your dynamic page via AJAX with some given query > 2. Modify the URL to match the query > 3. When a user accesses the same page with the given query > (my/page/?foo=bar) then they'll see the same thing > > Of course this will probably require modifying your view to accept queries. > > On Wed, May 23, 2012 at 11:23 AM, Furqan Malik > wrote: > > Thank you so much Lee, > > > > I am able to change the url but when i copy and past that url to new > > browser, it opens parent page. > > > > Any help? > > > > > > On Sat, May 19, 2012 at 10:49 AM, Lee Hinde wrote: > >> > >> > >> On May 18, 2012, at 8:24 PM, Furqan Malik wrote: > >> > >> Thanks for the reply, > >> > >> You misunderstood my question. > >> > >> Passed_TestCases = data['Data1']; > >> Failed_TestCases = data['Data2']; > >> These values are fine, I am using them to create the table. > >> > >> My question is once these values come from view.py, I want to change the > >> browser url so that url can be send to others. > >> > >> > >> You're right, I did. > >> > >> > >> > http://stackoverflow.com/questions/136458/change-the-url-in-the-browser-without-loading-the-new-page-using-javascript > >> > >> > >> > >> On Fri, May 18, 2012 at 3:52 PM, Lee Hinde wrote: > >>> > >>> > >>> On May 18, 2012, at 11:52 AM, furqanmlk wrote: > >>> > >>> Hi there, > >>> > >>> I implemented the JQuery to get the data from Database server and > display > >>> in the form of table on the page when user click one of the DOM > element. > >>> I tried , > >>> > >>> JQuery Code: > >>> $.get("RunId_TestCases",{Variable:Value},function(data){ > >>> > >>> > >>> Passed_TestCases = data['Data1']; > >>> Failed_TestCases = data['Data2']; > >>> //window.location.hash = this.url > >>>//window.location.assign(this.url) > >>> > >>> > >>> > >>> not knowing anything about the page, but you want something more like: > >>> > >>> $("#ID_FOR_THE_FIELD").val(data['Data1']); > >>> > >>> > >>> using window.location browser url gets changed but page goes to empty > >>> page with data values. > >>> > >>> > >>> Can you please help to solve this issue. > >>> > >>> > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "Django users" group. > >> To post to this group, send email to django-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. > > > > > > -- > > 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. > > -- > 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. > > -- 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: JQuery .get new url is not updating the page
I'm not sure of the use-case on this but you could possibly take the following approach: 1. Get your dynamic page via AJAX with some given query 2. Modify the URL to match the query 3. When a user accesses the same page with the given query (my/page/?foo=bar) then they'll see the same thing Of course this will probably require modifying your view to accept queries. On Wed, May 23, 2012 at 11:23 AM, Furqan Malik wrote: > Thank you so much Lee, > > I am able to change the url but when i copy and past that url to new > browser, it opens parent page. > > Any help? > > > On Sat, May 19, 2012 at 10:49 AM, Lee Hinde wrote: >> >> >> On May 18, 2012, at 8:24 PM, Furqan Malik wrote: >> >> Thanks for the reply, >> >> You misunderstood my question. >> >> Passed_TestCases = data['Data1']; >> Failed_TestCases = data['Data2']; >> These values are fine, I am using them to create the table. >> >> My question is once these values come from view.py, I want to change the >> browser url so that url can be send to others. >> >> >> You're right, I did. >> >> >> http://stackoverflow.com/questions/136458/change-the-url-in-the-browser-without-loading-the-new-page-using-javascript >> >> >> >> On Fri, May 18, 2012 at 3:52 PM, Lee Hinde wrote: >>> >>> >>> On May 18, 2012, at 11:52 AM, furqanmlk wrote: >>> >>> Hi there, >>> >>> I implemented the JQuery to get the data from Database server and display >>> in the form of table on the page when user click one of the DOM element. >>> I tried , >>> >>> JQuery Code: >>> $.get("RunId_TestCases",{Variable:Value},function(data){ >>> >>> >>> Passed_TestCases = data['Data1']; >>> Failed_TestCases = data['Data2']; >>> //window.location.hash = this.url >>> //window.location.assign(this.url) >>> >>> >>> >>> not knowing anything about the page, but you want something more like: >>> >>> $("#ID_FOR_THE_FIELD").val(data['Data1']); >>> >>> >>> using window.location browser url gets changed but page goes to empty >>> page with data values. >>> >>> >>> Can you please help to solve this issue. >>> >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To post to this group, send email to django-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. > > > -- > 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. -- 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: JQuery .get new url is not updating the page
Thank you so much Lee, I am able to change the url but when i copy and past that url to new browser, it opens parent page. Any help? On Sat, May 19, 2012 at 10:49 AM, Lee Hinde wrote: > > On May 18, 2012, at 8:24 PM, Furqan Malik wrote: > > Thanks for the reply, > > You misunderstood my question. > > Passed_TestCases = data['Data1']; > Failed_TestCases = data['Data2']; > These values are fine, I am using them to create the table. > > My question is once these values come from view.py, I want to change the > browser url so that url can be send to others. > > > You're right, I did. > > > http://stackoverflow.com/questions/136458/change-the-url-in-the-browser-without-loading-the-new-page-using-javascript > > > > On Fri, May 18, 2012 at 3:52 PM, Lee Hinde wrote: > >> >> On May 18, 2012, at 11:52 AM, furqanmlk wrote: >> >> Hi there, >> >> I implemented the JQuery to get the data from Database server and display >> in the form of table on the page when user click one of the DOM element. >> I tried , >> >> *JQuery Code:* >> $.get("RunId_TestCases",{Variable:Value},function(data){ >> >> >> Passed_TestCases = data['Data1']; >> Failed_TestCases = data['Data2']; >> //window.location.hash = this.url >>//window.location.assign(this.url) >> >> >> >> not knowing anything about the page, but you want something more like: >> >> $("#ID_FOR_THE_FIELD").val(data['Data1']); >> >> >> using window.location browser url gets changed but page goes to empty >> page with data values. >> >> >> Can you please help to solve this issue. >> >> >> > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-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. > -- 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: Need Help with ForeignKeys
Thanks! I think I understand it now! Mark On Wed, May 23, 2012 at 8:00 AM, Simone Federici wrote: > On Wed, May 23, 2012 at 4:40 PM, Mark Phillips > wrote: > >> Now, can you please explain why it worked? What does the related_name do >> and why do I need it? > > When you define a ForeignKey, django creates dinamically a reverse > relationship. > > take this example: > A > B.a -> A > > > from an instance of b = B() > you can arrive to the related instance of A by b.a > > but you can also from the instance of a = A() > retrieve all instace related of B by a.b_set() > > but if in a model there are two or more relationship versus the same model > the names clashed! and Django ask you to give their names by related_name > property. > > in your code: > > t = Team() > > this give you all games where the team was the home team > t.homegame_set.all() > > this give you all games where the team was the visitor team > t.vititorgame_set.all() > > > by default > t.game_set clash! > > -- > 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. > -- 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: Need Help with ForeignKeys
On Wed, May 23, 2012 at 4:40 PM, Mark Phillips wrote: > Now, can you please explain why it worked? What does the related_name do > and why do I need it? When you define a ForeignKey, django creates dinamically a reverse relationship. take this example: A B.a -> A from an instance of b = B() you can arrive to the related instance of A by b.a but you can also from the instance of a = A() retrieve all instace related of B by a.b_set() but if in a model there are two or more relationship versus the same model the names clashed! and Django ask you to give their names by related_name property. in your code: t = Team() this give you all games where the team was the home team t.homegame_set.all() this give you all games where the team was the visitor team t.vititorgame_set.all() by default t.game_set clash! -- 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: Need Help with ForeignKeys
The related name, basically, specifies a way to back-reference that particular Team. If you don't specify it, it just uses an automatically generated variable name (for example, just 'team'). You'd have a conflict because there'd be two 'team' variables generated in your game class. The method Simone shared basically just says We need foreign keys to Team objects, but we're going to call them 'homegame_set' and 'visitinggame_set'. Documentation here: https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.related_name On Wed, May 23, 2012 at 10:40 AM, Mark Phillips wrote: > Thanks, that worked. > > Now, can you please explain why it worked? What does the related_name do and > why do I need it? > > Thanks! > > Mark > > > On Wed, May 23, 2012 at 7:34 AM, Simone Federici > wrote: >> >> class Game(models.Model): >> game_id = models.IntegerField(primary_key=True) >> gamedate = models.DateField() >> gamestart = models.TimetField(blank=True) >> duration = models.IntegerField() >> innings = models.IntegerField() >> hometeam = models.ForeignKey(Team, related_name='homegame_set') >> visitingteam = models.ForeignKey(Team, >> related_name='visitinggame_set') >> >> >> -- >> 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. > > > -- > 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. -- 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 get text of a ChoiceField populated with ajax
Sorry, somehow I completely overlooked the post where it says you've solved the problem. Happy hacking! On Wed, May 23, 2012 at 10:52 AM, Kurtis Mullins wrote: > Hey, no problem! My apologies for missing out on this thread for a > while. I hope you got it figured out! > > Anyways, I'm thinking that if you're actually basing this validation > (done in your clean method), you may want to use a ForeignKey Field. > You can define a custom queryset to filter through the results if you > only want certain teachers to be available. > > Otherwise, you could put a method along these lines in your current Form > class. > > import Teacher > from (some django forms module) import ValidationError > class MyForm(Form): > > ... > def clean__teacher(self): > teacher = self.cleaned_data['teacher'] # Value of the chosen teacher > if Teacher.objects.filter(name=teacher).exists(): > return True > else > raise ValidationError("You have chosen an invalid teacher") > > Hopefully that helps a bit. If not, let me know and I'll try to help > some more :) > > On Fri, May 18, 2012 at 2:57 AM, HDayi wrote: >> hi curtis, >> sorry for being so late. >> >> on the page i have given the url, it's told exactly how you said. I have >> subclassed djangos choicefield and just changed validation method that >> always return true. so my own clean_fieldname method started to work fine. I >> am checking the returned valu if exist in my database table. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/django-users/-/Y_isSMVE4lcJ. >> >> 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. -- 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 get text of a ChoiceField populated with ajax
Hey, no problem! My apologies for missing out on this thread for a while. I hope you got it figured out! Anyways, I'm thinking that if you're actually basing this validation (done in your clean method), you may want to use a ForeignKey Field. You can define a custom queryset to filter through the results if you only want certain teachers to be available. Otherwise, you could put a method along these lines in your current Form class. import Teacher from (some django forms module) import ValidationError class MyForm(Form): ... def clean__teacher(self): teacher = self.cleaned_data['teacher'] # Value of the chosen teacher if Teacher.objects.filter(name=teacher).exists(): return True else raise ValidationError("You have chosen an invalid teacher") Hopefully that helps a bit. If not, let me know and I'll try to help some more :) On Fri, May 18, 2012 at 2:57 AM, HDayi wrote: > hi curtis, > sorry for being so late. > > on the page i have given the url, it's told exactly how you said. I have > subclassed djangos choicefield and just changed validation method that > always return true. so my own clean_fieldname method started to work fine. I > am checking the returned valu if exist in my database table. > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/Y_isSMVE4lcJ. > > 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. -- 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: Need Help with ForeignKeys
Thanks, that worked. Now, can you please explain why it worked? What does the related_name do and why do I need it? Thanks! Mark On Wed, May 23, 2012 at 7:34 AM, Simone Federici wrote: > class Game(models.Model): > game_id = models.IntegerField(primary_key=True) > gamedate = models.DateField() > gamestart = models.TimetField(blank=True) > duration = models.IntegerField() > innings = models.IntegerField() > hometeam = models.ForeignKey(Team, related_name='homegame_set') > visitingteam = models.ForeignKey(Team, related_name='visitinggame_set') > > > -- > 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. > -- 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: After python upgrade, User.objects.get(username= doesn't work consistently
Wow, nice find! I would've never thought an index would cause that sort of a problem. I'm glad you figured it out and thanks for sharing that crazy find! On Wed, May 23, 2012 at 4:23 AM, Hanne Moa wrote: > On 23 May 2012 00:30, akaariai wrote: >> On May 22, 11:49 pm, Hanne Moa wrote: >>> I upgraded python to 2.6.8 today from an earlier 2.6, what an >>> adventure! So much bizarre happenings so many places. >> >> Please provide these three things for further debugging: >> - the exact Python code you try in the shell (including a real >> username). >> - the SQL that generates (when not working). >> - what does happen when you try to run that SQL in manage.py dbshell >> (you might need to add quotes to the parameters) > > Problem solved. Exact lookups worked only intermittently in the > database as well. Turns out the index on usernames was hosed. I remade > it... > > alter table auth_user drop constraint auth_user_username_key; > alter table auth_user add constraint auth_user_username_key UNIQUE (username); > > and now it works. For a little while it was possible to make duplicate > users though (!) This calls for champagne, I've never seen an error in > the database that failed so spectacularly silently before =D > > > HM > > -- > 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. > -- 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.
I need a django application to embed a chat javascript in admin site
Hi everybody, I need a django application to embed a chat javascript in the admin app of my web site, I would like when the users are authenticated be able to contact by chat any other user authenticated in the admin site. How could I do this ??? Is there an application to make this ??? Regards, Ariel -- 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: Need Help with ForeignKeys
class Game(models.Model): game_id = models.IntegerField(primary_key=True) gamedate = models.DateField() gamestart = models.TimetField(blank=True) duration = models.IntegerField() innings = models.IntegerField() hometeam = models.ForeignKey(Team, related_name='homegame_set') visitingteam = models.ForeignKey(Team, related_name='visitinggame_set') -- 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.
Need Help with ForeignKeys
I have two tables - Team and Game. class Team(models.Model): team_id = models.IntegerField(primary_key=True) teamname = models.CharField(max_length=255) division_id = models.ForeignKey(Division) class Game(models.Model): game_id = models.IntegerField(primary_key=True) gamedate = models.DateField() gamestart = models.TimetField(blank=True) duration = models.IntegerField() innings = models.IntegerField() hometeam_id = models.ForeignKey(Team) visitingteam_id = models.ForeignKey(Team) The problem arises due to the two team_id foreign keys in the Game model - hometeam _id and visitingteam_id. The error I get is: Error: One or more models did not validate: statistics.game: Accessor for field 'hometeam_id' clashes with related field 'Team.game_set'. Add a related_name argument to the definition for 'hometeam_id'. statistics.game: Accessor for field 'visitingteam_id' clashes with related field 'Team.game_set'. Add a related_name argument to the definition for 'visitingteam_id'. I looked up "related_name" argument, and tried related_name='team_id' for both ForeignKeys, and got even more errors. Error: One or more models did not validate: statistics.game: Accessor for field 'hometeam_id' clashes with field 'Team.team_id'. Add a related_name argument to the definition for 'hometeam_id'. statistics.game: Reverse query name for field 'hometeam_id' clashes with field 'Team.team_id'. Add a related_name argument to the definition for 'hometeam_id'. statistics.game: Accessor for field 'hometeam_id' clashes with related field 'Team.team_id'. Add a related_name argument to the definition for 'hometeam_id'. statistics.game: Reverse query name for field 'hometeam_id' clashes with related field 'Team.team_id'. Add a related_name argument to the definition for 'hometeam_id'. statistics.game: Accessor for field 'visitingteam_id' clashes with field 'Team.team_id'. Add a related_name argument to the definition for 'visitingteam_id'. statistics.game: Reverse query name for field 'visitingteam_id' clashes with field 'Team.team_id'. Add a related_name argument to the definition for 'visitingteam_id'. statistics.game: Accessor for field 'visitingteam_id' clashes with related field 'Team.team_id'. Add a related_name argument to the definition for 'visitingteam_id'. statistics.game: Reverse query name for field 'visitingteam_id' clashes with related field 'Team.team_id'. Add a related_name argument to the definition for 'visitingteam_id'. I read the related names documentation referenced in the related_name description, and that did not help me understand what I need to do to fix this problem. I think I understand why django is getting confused by having two ForeignKeys referring to one primary key in another table, but I am not sure how to fix the problem. Thanks! Mark -- 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: Registering and authenticating via iPhone/Android app
On Wednesday, 23 May 2012 13:02:15 UTC+1, bruno desthuilliers wrote: > > On May 23, 1:12 pm, Roarster wrote: > > I'm developing a site using Django using the built in user > authentication > > module. This is all working fine and users can register, login, etc. on > > the web site with no problems. The plan is to also have companion > > iPhone/Android apps where users can register/login and then access their > > data on the main site. This is where I'm a bit unsure of how to > proceed. > > I've been looking into using TastyPie to create a REST API which I > think > > will work fine for accessing/updating data but I'm not sure if this is > > appropriate for creating new users and authenticating existing users. > > I'm definitly not an expert when it comes to mobile apps, but there > are quite a few known REST (or XMLRPC or else) APIs around that > include at least user authentication - think google (including > youtube, blogger etc), dailymotion, most blogging platforms, etc. > > As far as I'm concerned, I'd definitly use the API for authentication > too (possibly using OAuth). wrt/ registration, well, I have not > checked if any of the above APIs support this, but from your Django > app's POV, it's still all about HTTP requests / responses anyway so > well... > > My 2 cents, really.. Thanks Bruno. I've had a bit more of a look into this and everyone seems to be using OAuth, as you mention. I did try to get this working with the Tastypie API but I couldn't really find any documentation and found it a bit of a struggle. I guess I'll have to look into this further. I've also looked into the public APIs you mention and none of them seem to allow registration (at least not on the public API). I guess since my API will be private (at least initially) I can do what I want, I was just hoping to find out what some other well used apps (e.g. Instagram) might use for communication. Do you think it's possible they just have another REST API they don't disclose? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/68UDvibDrpAJ. 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: TypeError Exception Value: coercing to Unicode: need string or buffer, dict found
It shows this line: File "C:\simuladores\..\simuladores\detector\views.py" in pdf 259. canvas.print_pdf(response, facecolor='w', edgecolor='w') File "C:\Python26\Lib\site-packages\matplotlib\backend_bases.py" in print_pdf 1334. return pdf.print_pdf(*args, **kwargs) In my code this line is: dir(canvas.print_pdf) canvas.print_pdf(response, facecolor='w', edgecolor='w') but I do not know about solving. On 23 maio, 09:37, kenneth gonsalves wrote: > On Wed, 2012-05-23 at 05:16 -0700, Waleria wrote: > > Exception Type: TypeError Exception Value: coercing to Unicode: need > > string or buffer, dict found > > you have to find out where in the code the error is coming. Then you > will find that you are passing a dict instead of a string. > -- > regards > Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: TypeError Exception Value: coercing to Unicode: need string or buffer, dict found
On Wed, 2012-05-23 at 05:16 -0700, Waleria wrote: > Exception Type: TypeError Exception Value: coercing to Unicode: need > string or buffer, dict found you have to find out where in the code the error is coming. Then you will find that you are passing a dict instead of a string. -- regards Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: ordering m2m query based on through table
On May 23, 2:36 pm, bruno desthuilliers wrote: > > The interaction between > > multiple references to same reverse foreign key relation in single > > queryset is somewhat hard to remember. Could you post the generated > > SQL? > > here you go - reformated for readability: > > SELECT > `blookcore_category`.`id`, > `blookcore_category`.`label` > FROM > `blookcore_category` > LEFT OUTER JOIN `blookcore_classification` > ON (`blookcore_category`.`id` = > `blookcore_classification`.`category_id`) > WHERE > `blookcore_classification`.`blook_id` = 118 > ORDER BY > `blookcore_classification`.`position` ASC > > I don't quite get why it uses a left outer join instead of the inner > join used when not adding the order by clause, but writing a working, > usable ORM is not exactly a piece of cake so I won't complain about > this ;). Anyway: the where clause still makes sure we only get the > relevant categories. Right you are about the query producing correct results. I should have checked that myself. I guess (again!) that the reason for the LEFT JOIN is this call in sql/ compiler.py:_setup_joins() self.query.promote_alias_chain(joins, self.query.alias_map[joins[0]].join_type == self.query.LOUTER) This seems to promote the join to outer join too aggressively, the promote_alias_chain call does not see that the join is constrained by other conditions already. I don't know if this has any practical effects, nor do I know how easy/hard this would be to fix. It could be as easy as just starting from the first new join generated by the _setup_joins() call, and leaving the pre-existing joins alone. If it is that easy, it should be fixed... - Anssi -- 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: Following multiple reverse relationships
On May 23, 3:06 pm, sk <6b656...@gmail.com> wrote: > > On May 22, 12:51 pm, sk <6b656...@gmail.com> wrote: > > > > If I have a hierarchy of models such that: > > > > class A(models.Model): > > > name = CharField(max_length=10) > > > > class B(models.Model): > > > name = CharField(max_length=10) > > > a= ForeignKey(A) > > > > class C(models.Model): > > > name = CharField(max_length=10) > > > b= ForeignKey(B) > > > > If I have an instance of C, as returned by: > > > > c = C.objects.get(pk=1) > > > > How do I get the name of A? > > > > I realise I can go via B, but I am hoping to be able to follow the > > > chain back to A from any arbitrary point in (a much longer) chain. > > > > For example: > > > If this was repeated up to F in an identical manner. > > > If I pass a function any instance from A to F I would want to return > > > A.name. > > > > I am sure there must be a simple way to get the root data, but I am > > > having trouble finding it. > > > You really do have to go through the relations through the chain - > > there is no direct links from C to A so it is impossible to just hop > > from C to A. > > > You can query the A instance by something like > > A.objects.filter(pk=B.objects.filter(pk=c.b_id)) - this should return > > the A instance in one query. (It might be you will need to use > > pk__in). > > > Or, you could use select_related or prefetch_related to do the > > fetching. > > > - Anssi- Hide quoted text - > > > - Show quoted text - > > Fair enough, thank you for your reply. > > I is it posible to 'follow the chain' without knowing the exact > instance you are in? for example can i get all foreign keys for a > given instance, then follow them? To be honest this is just for > interest now - I have implemented this with some hard-coding of how to > decide where you are in the 'tree'. You can check Model._meta.fields, Model._meta.get_field_by_name() etc. Do a dir(ModelClass._meta) in pdb and you should see what methods/ attributes are available. The ._meta is part of the private API, so there are no stability guarantees... The ._meta is what Django's ORM uses when checking what lookups are available, and which of them are foreign keys, reverse foreign keys etc. So, it should contain all the necessary information for you. - Anssi -- 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.
TypeError Exception Value: coercing to Unicode: need string or buffer, dict found
Hi, Anyone know how to solve this error? Exception Type: TypeError Exception Value: coercing to Unicode: need string or buffer, dict found Can you help me?? See mycode: http://dpaste.com/751460/ And see my Traceback: http://dpaste.com/750773/ 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: Following multiple reverse relationships
> On May 22, 12:51 pm, sk <6b656...@gmail.com> wrote: > > > > > > > If I have a hierarchy of models such that: > > > class A(models.Model): > > name = CharField(max_length=10) > > > class B(models.Model): > > name = CharField(max_length=10) > > a= ForeignKey(A) > > > class C(models.Model): > > name = CharField(max_length=10) > > b= ForeignKey(B) > > > If I have an instance of C, as returned by: > > > c = C.objects.get(pk=1) > > > How do I get the name of A? > > > I realise I can go via B, but I am hoping to be able to follow the > > chain back to A from any arbitrary point in (a much longer) chain. > > > For example: > > If this was repeated up to F in an identical manner. > > If I pass a function any instance from A to F I would want to return > > A.name. > > > I am sure there must be a simple way to get the root data, but I am > > having trouble finding it. > > You really do have to go through the relations through the chain - > there is no direct links from C to A so it is impossible to just hop > from C to A. > > You can query the A instance by something like > A.objects.filter(pk=B.objects.filter(pk=c.b_id)) - this should return > the A instance in one query. (It might be you will need to use > pk__in). > > Or, you could use select_related or prefetch_related to do the > fetching. > > - Anssi- Hide quoted text - > > - Show quoted text - Fair enough, thank you for your reply. I is it posible to 'follow the chain' without knowing the exact instance you are in? for example can i get all foreign keys for a given instance, then follow them? To be honest this is just for interest now - I have implemented this with some hard-coding of how to decide where you are in the 'tree'. Many thanks Stephen -- 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: Registering and authenticating via iPhone/Android app
On May 23, 1:12 pm, Roarster wrote: > I'm developing a site using Django using the built in user authentication > module. This is all working fine and users can register, login, etc. on > the web site with no problems. The plan is to also have companion > iPhone/Android apps where users can register/login and then access their > data on the main site. This is where I'm a bit unsure of how to proceed. > I've been looking into using TastyPie to create a REST API which I think > will work fine for accessing/updating data but I'm not sure if this is > appropriate for creating new users and authenticating existing users. I'm definitly not an expert when it comes to mobile apps, but there are quite a few known REST (or XMLRPC or else) APIs around that include at least user authentication - think google (including youtube, blogger etc), dailymotion, most blogging platforms, etc. As far as I'm concerned, I'd definitly use the API for authentication too (possibly using OAuth). wrt/ registration, well, I have not checked if any of the above APIs support this, but from your Django app's POV, it's still all about HTTP requests / responses anyway so well... My 2 cents, really.. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Is there a custom forms component of python-web?
On May 23, 12:27 pm, kevon wang wrote: > Is there a component as above Yes. > thanks! You're welcome. hint #1: google is your friend. Took me about 15 seconds to get the answer, so way less than the time you spent posting your question. hint #2: what you're looking for is usally named a form builder. hint #3: Django and Python peoples are usually much more friendly than the average programmers group, but not doing your homework is still not an option. If you hope to get answers, at least explain what you already tried to solve your problem by yourself. -- 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.
Registering and authenticating via iPhone/Android app
Apologies if this has been asked before but I'm struggling to find any real best practices. I'm developing a site using Django using the built in user authentication module. This is all working fine and users can register, login, etc. on the web site with no problems. The plan is to also have companion iPhone/Android apps where users can register/login and then access their data on the main site. This is where I'm a bit unsure of how to proceed. I've been looking into using TastyPie to create a REST API which I think will work fine for accessing/updating data but I'm not sure if this is appropriate for creating new users and authenticating existing users. The other alternative would be (I think) to create a login form in the app which posts to my web site log in form and will return the usual session cookie. The registration form could do something similar again directly posting to the view rather than accessing the API. Does anyone have any opinions as to which of these options are best? I kind of feel using an API would be consistent with how the rest of the app will work but the lack of any examples of this on the internet leaves me wondering if this is a bad idea. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/mlu3FyMtvf4J. 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: ordering m2m query based on through table
On May 23, 11:43 am, akaariai wrote: > I would guess you would get duplicate objects returned. We programmers are usually very bad at guessing. So when in doubt, check, don't guess ;) > I think the > query works as follows: > - Fetch all Blook's categories > - For those categories you fetch all the classifications (not only > those which are related to Blook) and order by the position in there. Not quite - cf the generated SQL below. > So, you could get the same category multiple times ordered by > positions not related to the blook <-> category connection. That's not the case. Demonstration: First, check that we do have categories shared by multiples blooks (else it wouldn't mean much): >>> for blook in blooks: ... print blook, blook.categories.order_by("id").values_list("id", flat=True) ... #139 [533L, 534L, 535L, 536L, 537L, 538L, 539L, 540L, 541L, 542L, 543L, 544L, 545L, 546L, 547L] #129 [534L, 535L, 537L, 539L, 540L, 542L, 543L, 544L, 545L, 546L, 547L] #128 [534L] #126 [533L, 534L, 535L, 536L, 537L, 538L, 539L, 540L, 541L, 542L, 543L, 544L, 545L, 546L, 547L] #127 [533L, 534L, 535L, 536L, 537L, 538L, 539L, 540L, 541L, 542L, 543L, 544L, 545L, 546L, 547L] #118 [534L] Now check that for each blook, we have the same categories whether sorted or unsorted: >>> for blook in blooks: ... cats = blook.categories.all() ... scats = blook.sorted_categories ... assert set(cats) == set(scats), "OOPS ??? %s" % blook ... Well... No AssertionError raised, so it's correct. > Maybe the above code does work correctly. It does. Custom ordering is possibly one of the most common use case for "through" m2ms, so you can bet it works - else there would have been quite some criticism about it ;) > The interaction between > multiple references to same reverse foreign key relation in single > queryset is somewhat hard to remember. Could you post the generated > SQL? here you go - reformated for readability: SELECT `blookcore_category`.`id`, `blookcore_category`.`label` FROM `blookcore_category` LEFT OUTER JOIN `blookcore_classification` ON (`blookcore_category`.`id` = `blookcore_classification`.`category_id`) WHERE `blookcore_classification`.`blook_id` = 118 ORDER BY `blookcore_classification`.`position` ASC I don't quite get why it uses a left outer join instead of the inner join used when not adding the order by clause, but writing a working, usable ORM is not exactly a piece of cake so I won't complain about this ;). Anyway: the where clause still makes sure we only get the relevant categories. HTH -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Is there a custom forms component of python-web?
Is there a component as above, 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: JQuery Django
Thank you -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/qGTuZfj5344J. 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: "Connection refused" with backend psycopg2
Am 23.05.2012 11:34, schrieb akaariai: > On May 23, 11:46 am, Tanuva wrote: >> If I connect manually using psql, I automatically get an ssl connection. >> Non-ssl isn't supposed to work in this case. Removing the sslmode from >> the django config doesn't change anything as I noted in the paste. >> >>> The error you are getting is the same you get if you would try to >>> connect to a machine with no postgres installation at all. So, one >>> possibility is that your host or port are not correct for some reason. >> >> Thats what puzzles me: if I use psycopg2 by hand >> (http://dpaste.org/Ozisz/), the connection works fine with the same >> credentials I supplied to Django. The table I created there appears in >> pgadmin. >> >> Marcel > > Put a breakpoint in django/db/backends/postgresql_psycopg2/ > base.py:_cursor() and see what the connect parameters are. Double > check pg_hba.conf and postgresql.conf and make sure they allow you to > connect from the webapp machine to the DB. > > It is hard to help you more through a mailing list. > > - Anssi > That led me to the solution. After fiddling a little with the code, I noticed something: the server domain was blacklight-it.com. Therefore it is definitely not sufficient to use blacklight.com as the domain. And I didn't notice that all the time I looked at the Django config. (head->table)^n Thanks a lot for your effort and sorry for wasting your time... Marcel -- 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: ordering m2m query based on through table
On May 23, 12:12 pm, bruno desthuilliers wrote: > On May 22, 4:34 pm, akaariai wrote: > > > So, you would want to do collection.songs.all() and have that ordered > > by the sequence defined in the m2m table? I agree - this seems to be > > somewhat hard currently. > > I currently have a similar scheme in one of our projects, works fine > as far as I can tell: > > class Categorie(Model): > # > > class Blook(Model): > # > categories = models.ManyToManyField( > Category, > through='Classification', > related_name="blooks", > ) > > @property > def sorted_categories(self): > return self.categories.order_by("classifications__position") > > class Classification(Model): > category = models.ForeignKey( > Category, > related_name="classifications" > ) > > blook = models.ForeignKey( > Blook, > related_name="classifications" > ) > > position = models.PositiveIntegerField( > _(u"Position"), > ) > > class Meta: > unique_together = ( > ("blook", "category"), > ("blook", "position"), > ) I would guess you would get duplicate objects returned. I think the query works as follows: - Fetch all Blook's categories - For those categories you fetch all the classifications (not only those which are related to Blook) and order by the position in there. So, you could get the same category multiple times ordered by positions not related to the blook <-> category connection. Maybe the above code does work correctly. The interaction between multiple references to same reverse foreign key relation in single queryset is somewhat hard to remember. Could you post the generated SQL? - Anssi -- 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: "Connection refused" with backend psycopg2
On May 23, 11:46 am, Tanuva wrote: > If I connect manually using psql, I automatically get an ssl connection. > Non-ssl isn't supposed to work in this case. Removing the sslmode from > the django config doesn't change anything as I noted in the paste. > > > The error you are getting is the same you get if you would try to > > connect to a machine with no postgres installation at all. So, one > > possibility is that your host or port are not correct for some reason. > > Thats what puzzles me: if I use psycopg2 by hand > (http://dpaste.org/Ozisz/), the connection works fine with the same > credentials I supplied to Django. The table I created there appears in > pgadmin. > > Marcel Put a breakpoint in django/db/backends/postgresql_psycopg2/ base.py:_cursor() and see what the connect parameters are. Double check pg_hba.conf and postgresql.conf and make sure they allow you to connect from the webapp machine to the DB. It is hard to help you more through a mailing list. - Anssi -- 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: DB joining 3 tables in django admin, while searching on the primary table
On May 20, 9:42 am, Aditya Sriram M wrote: > I tried this but it failed? Can you pls correct me? yes : "it failed" is the worst possible way to describe a problem if you expect to get some help. If you get an exception and traceback, please read them carefully, and eventually post them. Else at least describe the (unexpected) result. > where definition of 'get_user_name' is > > def get_user_name(self, obj): > return u'%s %s %s' % (obj.customerid__first_name, > obj.customerid__middle_name, obj.customerid__last_name) What do you expect "obj.customerid__first_name" to eval to exactly ? > where 'first_name', 'middle_name' etc are properties of the 'User' model. http://en.wikipedia.org/wiki/Programming_by_permutation ? I'm sorry to have to say, but it definitly looks like you just don't have a clue about how Python and Django work. Please take time to learn at least Python 101, then do Django tutorial. This should answer your questions and save everyone time on such issues. -- 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: ordering m2m query based on through table
On May 22, 4:34 pm, akaariai wrote: > So, you would want to do collection.songs.all() and have that ordered > by the sequence defined in the m2m table? I agree - this seems to be > somewhat hard currently. I currently have a similar scheme in one of our projects, works fine as far as I can tell: class Categorie(Model): # class Blook(Model): # categories = models.ManyToManyField( Category, through='Classification', related_name="blooks", ) @property def sorted_categories(self): return self.categories.order_by("classifications__position") class Classification(Model): category = models.ForeignKey( Category, related_name="classifications" ) blook = models.ForeignKey( Blook, related_name="classifications" ) position = models.PositiveIntegerField( _(u"Position"), ) class Meta: unique_together = ( ("blook", "category"), ("blook", "position"), ) -- 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: Django site updater
git (or whatever versioning system you're using) + South for schema migrations + virtualenv / pip for depencies + a simple shell script on the server to update the whole damn thing and restart services (Apache, whatever). You can even have the script run by a cron job so the server is updated every night. -- 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: "Connection refused" with backend psycopg2
Am 23.05.2012 08:06, schrieb akaariai: > On May 23, 8:41 am, Tanuva wrote: >> Am 22.05.2012 23:52, schrieb akaariai: >> >> >> >> >> >> >> >> >> >>> On May 22, 11:51 pm, Tanuva wrote: Moin, >> lately, I wanted to switch my database from the testing sqlite file to a more productive pgsql 8.4 server. Now I'm constantly getting a "connection refused" from the psycopg2 backend:http://dpaste.org/0Ezka/ Database configuration:http://dpaste.org/QPjD2/(notthat verbose...) >> Funny enough, connecting manually using psycopg2 in a python2 shell and using pgadmin to confirm changes done there works just fine, so there must be something in between. >> What information might help you help me helping myself? ;) >> >>> I would take a wild guess that this is related to pg_hba.conf. Is the >>> database on the localhost? If so, can you connect to it using 'psql -d >>> thedb', but not with 'psql -d thedb -h www0.com -U >>> the_user_in_settings'. >> >>> - Anssi >> >> No, the db is not running on localhost, the machine sits in some >> datacentre. On that db server, your first command indeed doesn't work. >> Sadly that doesn't tell us much now I guess. The second one works fine >> both on the machine and here on my local box. > > Maybe the psql -d thedb should not work. On the db server you should > probably add -U in there. > > Maybe the 'sslmode': 'require' is causing this problem? You can try if > this is causing problem by: > export SSLMODE=required > psql -U -h -p 5432 > or by just removing the sslmode from your database settings and trying > again. If I connect manually using psql, I automatically get an ssl connection. Non-ssl isn't supposed to work in this case. Removing the sslmode from the django config doesn't change anything as I noted in the paste. > The error you are getting is the same you get if you would try to > connect to a machine with no postgres installation at all. So, one > possibility is that your host or port are not correct for some reason. Thats what puzzles me: if I use psycopg2 by hand (http://dpaste.org/Ozisz/), the connection works fine with the same credentials I supplied to Django. The table I created there appears in pgadmin. Marcel -- 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: After python upgrade, User.objects.get(username= doesn't work consistently
On 23 May 2012 00:30, akaariai wrote: > On May 22, 11:49 pm, Hanne Moa wrote: >> I upgraded python to 2.6.8 today from an earlier 2.6, what an >> adventure! So much bizarre happenings so many places. > > Please provide these three things for further debugging: > - the exact Python code you try in the shell (including a real > username). > - the SQL that generates (when not working). > - what does happen when you try to run that SQL in manage.py dbshell > (you might need to add quotes to the parameters) Problem solved. Exact lookups worked only intermittently in the database as well. Turns out the index on usernames was hosed. I remade it... alter table auth_user drop constraint auth_user_username_key; alter table auth_user add constraint auth_user_username_key UNIQUE (username); and now it works. For a little while it was possible to make duplicate users though (!) This calls for champagne, I've never seen an error in the database that failed so spectacularly silently before =D HM -- 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: JQuery Django
This might be helpful: http://www.djangobook.com/en/beta/chapter04/ On Wed, May 23, 2012 at 4:06 PM, cocoza4 wrote: > I'm new to Django. > How can i connect Django with jQuery? > > is there any additional tool that i need to install? > > could you show me a sample code also? > > Thanks in advance. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/OIGnCdgMJooJ. > 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. -- 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.