Retrieve Data from Database

2012-07-24 Thread Madhu
Hi!
I am new in django, i want to get the table from one table also want the 
some content from another table.
Can anybody tell me how it should be done?

My module class structure is as below

class A(models.Model): 
name =models.CharField(max_length=100)
content = models.CharField(max_length=100)
B = models.ForeignKey(B) 

class B(models.Model): 
   details =models.CharField(max_length=100)

i want to display the details from table A as name, content also wants to 
display details from table B.

-- 
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/-/wqLW58kbqfEJ.
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: Retrieve Data from Database

2012-07-24 Thread Daniel Roseman
On Tuesday, 24 July 2012 08:00:02 UTC+1, Madhu wrote:
>
> Hi!
> I am new in django, i want to get the table from one table also want the 
> some content from another table.
> Can anybody tell me how it should be done?
>
> My module class structure is as below
>
> class A(models.Model): 
> name =models.CharField(max_length=100)
> content = models.CharField(max_length=100)
> B = models.ForeignKey(B) 
>
> class B(models.Model): 
>details =models.CharField(max_length=100)
>
> i want to display the details from table A as name, content also wants to 
> display details from table B.
>


What, exactly, are you having trouble with? What have you tried?

I see you also commented on a three-year-old post of mine answering a very 
similar question. What about that answer did not help you?
--
DR.

-- 
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/-/NcMMP9XhasEJ.
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.



ForeignKey as dropdown list, get user's choice

2012-07-24 Thread mapapage
Hello!
I have a form including a field: veh_id1 = models.ForeignKey(Vehicles)) 
that is being rendered on the template as dropdown list.
Now I want according to the user's choice in that list some other fields of 
my form to be auto-completed and displayed on the template before the form 
submission.
I guess that I should use ajax for that. But I really don't know how I will 
access that user's choice in veh_id1 since it's not rendered as a classic 
html select and I don't have id for each choice etc. Sry if my question is 
dump but I'm new to all that and now I'm stuck.

-- 
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/-/F6XpJXQ70UoJ.
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: Difficulties using generic views (Tutorial 4, Django 1.4)

2012-07-24 Thread Rob
Sometimes the browser cache is making trouble too. Especially with Firefox 
I occasionally have this kind of problems. Clear the browser cache, or test 
with a different browser mostly helps.

-- 
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/-/igIQbm0y6yoJ.
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.



forms.FileField

2012-07-24 Thread francescobocca...@libero.it
Hi all,
i have a question about Form. I create a template that use a forms.FileField 
(text) and  forms.FileField to upload a file.
I fill a forms.FileField field and forms.FileField. I upload the file without 
errors but when the page is reaload only forms.FileField is filled with last 
text while forms.FileField is empty. Is there a way to remember the path of my 
last file uploaded?
Thanks

Francesco

-- 
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: forms.FileField

2012-07-24 Thread Karen Tracey
On Tue, Jul 24, 2012 at 8:05 AM, francescobocca...@libero.it <
francescobocca...@libero.it> wrote:

> Hi all,
> i have a question about Form. I create a template that use a
> forms.FileField
> (text) and  forms.FileField to upload a file.
> I fill a forms.FileField field and forms.FileField. I upload the file
> without
> errors but when the page is reaload only forms.FileField is filled with
> last
> text while forms.FileField is empty. Is there a way to remember the path
> of my
> last file uploaded?
>

No. This is a browser security feature. Browsers do not allow file upload
fields to be initialized by the server, users must explicitly choose files
to be uploaded.

Karen
-- 
http://tracey.org/kmt/

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



R: Re: forms.FileField

2012-07-24 Thread francescobocca...@libero.it
Thanks,
Francesco


Messaggio originale

Da: kmtra...@gmail.com

Data: 24/07/2012 14.11

A: 

Ogg: Re: forms.FileField



On Tue, Jul 24, 2012 at 8:05 AM, francescobocca...@libero.it 
 wrote:

Hi all,

i have a question about Form. I create a template that use a forms.FileField

(text) and  forms.FileField to upload a file.

I fill a forms.FileField field and forms.FileField. I upload the file without

errors but when the page is reaload only forms.FileField is filled with last

text while forms.FileField is empty. Is there a way to remember the path of my

last file uploaded?

No. This is a browser security feature. Browsers do not allow file upload 
fields to be initialized by the server, users must explicitly choose files to 
be uploaded.

Karen 

-- 
http://tracey.org/kmt/







-- 

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.



Washington, D.C.

2012-07-24 Thread Andrew Moore
Seeking a senior Django developer with 5 years experience to develop 
applications for a world famous media company (think a century of 
incredible photographs and stories in its signature monthly magazine) in 
Washington, D.C. Job is permanent, with full benefits. Compensation would 
be approximately $110,000. 

-- 
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/-/DOI2KWhbwJ4J.
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: Washington, D.C.

2012-07-24 Thread Marcin Tustin
Unless I'm mistaken, they already posted an ad for this job to this list.

On Tue, Jul 24, 2012 at 9:43 AM, Andrew Moore wrote:

> Seeking a senior Django developer with 5 years experience to develop
> applications for a world famous media company (think a century of
> incredible photographs and stories in its signature monthly magazine) in
> Washington, D.C. Job is permanent, with full benefits. Compensation would
> be approximately $110,000.
>
> --
> 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/-/DOI2KWhbwJ4J.
> 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.
>



-- 
Marcin Tustin
Tel: 07773 787 105

-- 
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: ForeignKey as dropdown list, get user's choice

2012-07-24 Thread Dmitry Zimnukhov
First you say that the field "is being rendered on the template as
dropdown list", and then "it's not rendered as a classic html select"
How is it rendered? Isn't html select a drop-down list?
By the way models.ForeignKey is a model field, not a form field. How
is your form defined?

2012/7/24 mapapage :
> Hello!
> I have a form including a field: veh_id1 = models.ForeignKey(Vehicles)) that
> is being rendered on the template as dropdown list.
> Now I want according to the user's choice in that list some other fields of
> my form to be auto-completed and displayed on the template before the form
> submission.
> I guess that I should use ajax for that. But I really don't know how I will
> access that user's choice in veh_id1 since it's not rendered as a classic
> html select and I don't have id for each choice etc. Sry if my question is
> dump but I'm new to all that and now I'm stuck.
>
> --
> 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/-/F6XpJXQ70UoJ.
> 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 Display Non-Modal Popup From Resulting Asynchronous Javascript Request

2012-07-24 Thread curious1
OK. sorry for not providing more information previously. Currently here's 
the 404 I'm getting back when I submit the asynchronous request:

Page not found (404)

Request Method:
GET

Request URL:
http://127.0.0.1:8000/mediahelp/comphelp/mediaHelpPopup.html

 Using the URLconf defined in streamingmedia.urls, Django tried these URL 
patterns, in this order: 
1.^mymedia/
2.^mediaadmin/
3.^mediahelp/ ^$
4.^mediahelp/ ^comphelp/$
5.^admin/
The current URL, mediahelp/comphelp/mediaHelpPopup.html, didn't match any 
of these.
 
The code from the comphelp url view is very basic and looks like this:
def component_help(request):
view = "component_help"
dctnry = {}
reqGET = request.GET.copy()
if reqGET.has_key('fieldId'):
field_value = reqGET['fieldId']
else:
field_value = "NONE FOUND"
message = "This is a test message!...FIELD-ID="+field_value
dctnry['helpdata'] = message
return HttpResponse(message)
 
Currently I only have it set up to return a message just to prove that the 
call was made and returned  successfully. This is all very basic code at 
this point since I'm just trying to set up all of the needed functionality. 
Here's the html page in question:
 
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>


MEDIA-HELP POPUP SCREEN




 
Finally here are the javascript routines which are supposed to display the 
data returned in the popup:
 
function popup(responseData)
  {
 var href = "../../mediahelp/comphelp/mediaHelpPopup.html";  
 var windowname = "Super Admin Reports POPUP";   
  if(!window.focus)
  {
  return true;
  }
  helpdatascreen = window.open(href, 
windowname,'width=400,height=200,scrollbars=yes');
  helpdatascreen.body.appendChild = responseData;
  helpdatascreen.focus();
  return false;
  }
function displayHelpData()
  {  
  if(request.readyState == 4)
  {
  if(request.status == 200)
  
  {
  popup(request.responseText);
  } 
  }
  }
 
So is there a problem with the url used above(the href field in the popup 
function)? If so what's wrong with it? Previously the call seemed to be 
successfull as well as the return, since I was previously able to display 
the returned message in an alert. So I wanted to actually display the 
returned data in a popup window, which is my ultimate goal and that is 
where things stand so far in my progress, up to the point to where I 
started getting the current 404 situation that you now see above. Thanks 
for the help.
 

-- 
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/-/tG_pIDLXKyUJ.
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: phpBB3 to DjangoBB migration...

2012-07-24 Thread jens
jens wrote:
> The last thing to migrate is the topic subscriptions, but django can't
> handle the model. See: https://github.com/jedie/django-phpBB3/issues/5

This is now implemented with commit:
https://github.com/jedie/django-phpBB3/commit/2c4835fceb1c7dc8df30b1ef50b2cc06d4425f5c

So i think everything is done to migrate a phpBB forum to DjangoBB ;)

Mfg.

Jens

-- 
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 Display Non-Modal Popup From Resulting Asynchronous Javascript Request

2012-07-24 Thread Daniel Roseman
On Tuesday, 24 July 2012 15:03:49 UTC+1, curious1 wrote:
 

> So is there a problem with the url used above(the href field in the popup 
> function)? If so what's wrong with it? Previously the call seemed to be 
> successfull as well as the return, since I was previously able to display 
> the returned message in an alert. So I wanted to actually display the 
> returned data in a popup window, which is my ultimate goal and that is 
> where things stand so far in my progress, up to the point to where I 
> started getting the current 404 situation that you now see above. Thanks 
> for the help.
>
> 

What part of Tomas's reply didn't you understand? Yes, there is a problem 
with that URL, because it doesn't match any of the URLs in your urlconf. 
There is no URL matching anything ending in 'html'. Perhaps you meant just 
/mediahelp/comphelp/  ?
--
DR.

-- 
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/-/J6lir9QeY4IJ.
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: Query Distances from User

2012-07-24 Thread Melvyn Sopacua
On 15-7-2012 4:30, JJ Zolper wrote:

> So i was thinking maybe GeoIP might be good because it will use the users
> location and last known GeoIP of the artist for example.
> 
> I was curious if anyone had any ideas or better ideas then I had.

IP addresses are only good if the remote address matches the physical
location [1].

Using geolocation [2] is probably a better solution especially since the
user can opt-in with it, support is growing [3] and available in mobile
devices.

[1]

[2] 
[3] 
-- 
Melvyn Sopacua

-- 
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 Display Non-Modal Popup From Resulting Asynchronous Javascript Request

2012-07-24 Thread Tomas Neme
> The current URL, mediahelp/comphelp/mediaHelpPopup.html, didn't match any of
> these.
>
> The code from the comphelp url view is very basic and looks like this:
> def component_help(request):
> view = "component_help"
> dctnry = {}
> reqGET = request.GET.copy()
> if reqGET.has_key('fieldId'):
> field_value = reqGET['fieldId']
> else:
> field_value = "NONE FOUND"
> message = "This is a test message!...FIELD-ID="+field_value
> dctnry['helpdata'] = message
> return HttpResponse(message)

then why are you calling /mediahelp/comphelp/mediaHelpPopup.html?

what exactly do you think that html filename in the end does to your call?

And.. no, I could make a lot of questions trying to lead you slowly to
the answer, but what I really think is that you need to do the
tutorial again, and understand urlconfs, views and templates.
https://docs.djangoproject.com/en/dev/intro/tutorial01/

I'll give you the short of it because I'm not your teacher: what you
actually want to do is call '/mediahelp/comphelp/' and from the view
you'll want to `return render_to_response('mediaHelpPopup.html',
dctnry)`

-- 
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
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: Query Distances from User

2012-07-24 Thread JJ Zolper
Thank you for the great information!

Currently I'm focused on my desktop browser platform but if I move to 
mobile I'll consider GeoLocation!

JJ

On Tuesday, July 24, 2012 10:56:34 AM UTC-4, Melvyn Sopacua wrote:
>
> On 15-7-2012 4:30, JJ Zolper wrote: 
>
> > So i was thinking maybe GeoIP might be good because it will use the 
> users 
> > location and last known GeoIP of the artist for example. 
> > 
> > I was curious if anyone had any ideas or better ideas then I had. 
>
> IP addresses are only good if the remote address matches the physical 
> location [1]. 
>
> Using geolocation [2] is probably a better solution especially since the 
> user can opt-in with it, support is growing [3] and available in mobile 
> devices. 
>
> [1] 
> <
> http://serverfault.com/questions/125944/with-more-mobile-users-my-geo-ip-database-is-becoming-useless>
>  
>
> [2]  
> [3]  
> -- 
> Melvyn Sopacua 
>

-- 
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/-/BmaWSc19WBkJ.
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: Catch or raise exception designissue

2012-07-24 Thread Melvyn Sopacua
On 15-7-2012 21:30, Jani Tiainen wrote:

> In case of incorrect request I prefer to raise 400 (Bad Request) with some
> explanation what went wrong. Since 500 is usually meant for "catch all"
> unexpected errors that happened in web server and server can't be more
> precise what happened. I've done that according to RFC 2616 (HTTP 1.1
> Specification) where is said that 4xx codes are meant for "client side
> error" (Section 10.4), and 5xx which means "server error" (Section 10.5)

Yeah, this is one of the harder ones. Is it still a client error if she
clicks a server generated link? ;)

-- 
Melvyn Sopacua

-- 
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 Models: How to allow users to select an image from a choice of 3 pictures

2012-07-24 Thread Melvyn Sopacua
On 16-7-2012 3:26, croberts wrote:
> I am familiar with the use of Field.choices for text.

Then that's all you need. Let the template handle the image rendered:
EMO_CHOICES = (
('smiley_sad.png', 'sad sad emo'),
('smiley_neutral.png', 'ask me later'),
('smiley_happy.png', 'happy happy joy joy'),
)

in template:
{% load static %}
...


And of course you can dress it up as Ivan showed, but the basic
principles are the same.

-- 
Melvyn Sopacua

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



All of the sudden getting TemplateDoesNotExist error

2012-07-24 Thread rmschne
I have made no changes to settings.py. Honest.  I'm running Django 1.4.0 
alpha. The variable TEMPLATE_DIRS is pointing to a folder which exists and 
the template 'directory.html' i wish to load in in that 
folder, /Users/rmschne/Documents/source/django/projects/socmgmt/templates/. 
 My ID has appropriate permissions (running on Mac OS/X). 

All of the sudden today (and it worked  a few days ago), I get 
"TemplateDoesNotExist" error.  This happens for any of the templates I try 
to load.

Frankly, I'm at a kinda loss as to where to start debugging this since 
everything looks ok and I don't recall making any changes that would be 
relevants.

Thoughts?

-- 
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/-/YogUO9twskIJ.
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.



Discovering Artists through GeoDjango by referencing my Artists database

2012-07-24 Thread JJ Zolper


Hello fellow Django developers,


So here is my model that interfaces with my Artists database:




from django.db import models


class Artist(models.Model):

  name = models.CharField(max_length=30)

  genre = models.CharField(max_length=30) 

  city = models.CharField(max_length=30) 

  state = models.CharField(max_length=30) 

  country = models.CharField(max_length=30)

  website = models.UrlField()


  def __unicode__(self):

return self.name




Okay now that you see my database backend interface here's where I'm going 
next.


I've been working with GeoDjango for some time now. I've created an app 
within my GeoDjango project called "discover". What's my goal? Well, I want 
this app to be able to return

information to my users. This app will take the given parameters such as 
"locationfrom" (the user of the website inserts their city, state) and then 
that value is used to bring in the artists in their area in relation to the 
variable "requesteddistance" (which for example could be 25 mi) along with 
another variable "genre" (a query on the artists). So the picture is the 
user might say I want to see all the "Rock" artists "25 mi" from me in 
"Vienna, VA".


Now that you can see my project here, here is my question.


In my discover app in the models.py file I could use some help. Through 
this discover app I want to be able to reference the Artists database. As 
you can see from above the

models.py file has the fields to establish an Artist and their information. 
Thus, when a request comes in to the discover app I want to be able to 
calculate the requested information and return that. Here's where I'm 
stuck... 


In my mind I feel that the appropriate way to do this is to basically 
create some sort of ForeignKey in the models.py of discover to the 
models.py of Artist? That way I don't have to have two databases of the 
same data but can simply reference the Artist database from the discover 
app.


Another idea I had was instead of creating a "field" link between the two 
to try to import the Artist class from the models.py to the models.py file 
of the discover app? Then from my views.py file in discover I can process 
the given information referenced and return the result.


Any input is welcome. I am striving to use Django's DRY (Don't Repeat 
Yourself) methodolgy and try to reference the Artist database and do the 
actual processing in the discover application.


Thanks a lot for your advice,

JJ Zolper

-- 
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/-/fBEgEgm4qjAJ.
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.



Discovering Artists through GeoDjango by referencing my Artists database

2012-07-24 Thread JJ Zolper
Hello fellow Django developers,

So here is my model that interfaces with my Artists database:



from django.db import models

class Artist(models.Model):
  name = models.CharField(max_length=30)
  genre = models.CharField(max_length=30) 
  city = models.CharField(max_length=30) 
  state = models.CharField(max_length=30) 
  country = models.CharField(max_length=30)
  website = models.UrlField()

  def __unicode__(self):
return self.name



Okay now that you see my database backend interface here's where I'm going 
next.

I've been working with GeoDjango for some time now. I've created an app 
within my GeoDjango project called "discover". What's my goal? Well, I want 
this app to be able to return
information to my users. This app will take the given parameters such as 
"locationfrom" (the user of the website inserts their city, state) and then 
that value is used to bring in the artists in their area in relation to the 
variable "requesteddistance" (which for example could be 25 mi) along with 
another variable "genre" (a query on the artists). So the picture is the 
user might say I want to see all the "Rock" artists "25 mi" from me in 
"Vienna, VA".

Now that you can see my project here, here is my question.

In my discover app in the models.py file I could use some help. Through 
this discover app I want to be able to reference the Artists database. As 
you can see from above the
models.py file has the fields to establish an Artist and their information. 
Thus, when a request comes in to the discover app I want to be able to 
calculate the requested information and return that. Here's where I'm 
stuck... 

In my mind I feel that the appropriate way to do this is to basically 
create some sort of ForeignKey in the models.py of discover to the 
models.py of Artist? That way I don't have to have two databases of the 
same data but can simply reference the Artist database from the discover 
app.

Another idea I had was instead of creating a "field" link between the two 
to try to import the Artist class from the models.py to the models.py file 
of the discover app? Then from my views.py file in discover I can process 
the given information referenced and return the result.

Any input is welcome. I am striving to use Django's DRY (Don't Repeat 
Yourself) methodolgy and try to reference the Artist database and do the 
actual processing in the discover application.

Thanks a lot for your advice,

JJ Zolper

-- 
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/-/nnsb5jjHLPgJ.
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.



Discovering Artists through GeoDjango by referencing my Artists database

2012-07-24 Thread JJ Zolper
Hello fellow Django developers,

So here is my model that interfaces with my Artists database:



from django.db import models

class Artist(models.Model):
  name = models.CharField(max_length=30)
  genre = models.CharField(max_length=30) 
  city = models.CharField(max_length=30) 
  state = models.CharField(max_length=30) 
  country = models.CharField(max_length=30)
  website = models.UrlField()

  def __unicode__(self):
return self.name



Okay now that you see my database backend interface here's where I'm going 
next.

I've been working with GeoDjango for some time now. I've created an app 
within my GeoDjango project called "discover". What's my goal? Well, I want 
this app to be able to return
information to my users. This app will take the given parameters such as 
"locationfrom" (the user of the website inserts their city, state) and then 
that value is used to bring in the artists in their area in relation to the 
variable "requesteddistance" (which for example could be 25 mi) along with 
another variable "genre" (a query on the artists). So the picture is the 
user might say I want to see all the "Rock" artists "25 mi" from me in 
"Vienna, VA".

Now that you can see my project here, here is my question.

In my discover app in the models.py file I could use some help. Through 
this discover app I want to be able to reference the Artists database. As 
you can see from above the
models.py file has the fields to establish an Artist and their information. 
Thus, when a request comes in to the discover app I want to be able to 
calculate the requested information and return that. Here's where I'm 
stuck... 

In my mind I feel that the appropriate way to do this is to basically 
create some sort of ForeignKey in the models.py of discover to the 
models.py of Artist? That way I don't have to have two databases of the 
same data but can simply reference the Artist database from the discover 
app.

Another idea I had was instead of creating a "field" link between the two 
to try to import the Artist class from the models.py to the models.py file 
of the discover app? Then from my views.py file in discover I can process 
the given information referenced and return the result.

Any input is welcome. I am striving to use Django's DRY (Don't Repeat 
Yourself) methodolgy and try to reference the Artist database and do the 
actual processing in the discover application.

Thanks a lot for your advice,

JJ Zolper


-- 
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/-/ht2cfu74GawJ.
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.



Discovering Artists through GeoDjango by referencing my Artists database

2012-07-24 Thread JJ Zolper
Hello fellow Django developers,

So here is my model that interfaces with my Artists database:



from django.db import models

class Artist(models.Model):
  name = models.CharField(max_length=30)
  genre = models.CharField(max_length=30) 
  city = models.CharField(max_length=30) 
  state = models.CharField(max_length=30) 
  country = models.CharField(max_length=30)
  website = models.UrlField()

  def __unicode__(self):
return self.name



Okay now that you see my database backend interface here's where I'm going 
next.

I've been working with GeoDjango for some time now. I've created an app 
within my GeoDjango project called "discover". What's my goal? Well, I want 
this app to be able to return information to my users. This app will take 
the given parameters such as "locationfrom" (the user of the website 
inserts their city, state) and then that value is used to bring in the 
artists in their area in relation to the variable "requesteddistance" 
(which for example could be 25 mi) along with another variable "genre" (a 
query on the artists). So the picture is the user might say I want to see 
all the "Rock" artists "25 mi" from me in "Vienna, VA".

Now that you can see my project here, here is my question.

In my discover app in the models.py file I could use some help. Through 
this discover app I want to be able to reference the Artists database. As 
you can see from above the
models.py file has the fields to establish an Artist and their information. 
Thus, when a request comes in to the discover app I want to be able to 
calculate the requested information and return that. Here's where I'm 
stuck... 

In my mind I feel that the appropriate way to do this is to basically 
create some sort of ForeignKey in the models.py of discover to the 
models.py of Artist? That way I don't have to have two databases of the 
same data but can simply reference the Artist database from the discover 
app.

Another idea I had was instead of creating a "field" link between the two 
to try to import the Artist class from the models.py to the models.py file 
of the discover app? Then from my views.py file in discover I can process 
the given information referenced and return the result.

Any input is welcome. I am striving to use Django's DRY (Don't Repeat 
Yourself) methodolgy and try to reference the Artist database and do the 
actual processing in the discover application.

Thanks a lot for your advice,

JJ Zolper


-- 
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/-/bveITGLO17IJ.
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 Display Non-Modal Popup From Resulting Asynchronous Javascript Request

2012-07-24 Thread curious1

>
> Thanks for the help. You revealed some things to me which I hadn't 
> understood or tried before, but now I have. The 404 problem has been 
> resolved and things are working much better. Thanks again.

-- 
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/-/DaEgDYUkLbEJ.
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.



ManyToMany relationship with intermediate model and admin list display with each realtion with value as diferent column

2012-07-24 Thread Ignacio Soto
Hey guys

i have an issue, i don know if it really can be done.

im using django 1.3

i have a model producto(product) and Tienda(store)

and a product could be in one or more stores, so i created a many to many 
relationship but y have a stock in each store, so i use the intermediary 
model ProductStore.

i want to create this, in the admin , product's  list display, i want to 
show each manutomany relationship as a diferent column qith the stock as 
the value.





as shown in the picture, this i could do by add a method in the model 
getTienda1 and return the stock and do it for each store, but i want it to 
be created dinamically because the user could create a new store and it 
will not be there.

so this is my cuestion: can i do that?

(Sorry for my bad english)

-- 
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/-/whHmIGyht_IJ.
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: ManyToMany relationship with intermediate model and admin list display with each realtion with value as diferent column

2012-07-24 Thread Tomas Neme
> as shown in the picture, this i could do by add a method in the model
> getTienda1 and return the stock and do it for each store, but i want it to
> be created dinamically because the user could create a new store and it
will
> not be there.
>
> so this is my cuestion: can i do that?

Interesting question. You COULD try the following:

in the ProductAdmin ModelAdmin's class' __init__ you can define
list_display like

from store.models import Tienda
for store in Tienda.objects.all():
self.list_display.append('stock_tienda_{id}'.format(id=store.id))

this would give you the list of existing stores at server init time.
and then you could define your Product model's __getattr__ method something
like this:

def __getattr__(self, attr):
 base = 'stock_tienda_'
 if attr[:len(base)] == base:
 return
Product.objects.filter(tienda=Tienda.objects.get(id=attr[len(base):]))
 return super(Product, self).__getattr__(self, attr)

this should make the ModelAdmin's hack work

finally, you need a way to add new columns for newly created stores, so
maybe a post_save signal on Tienda objects

@receiver(post_save, sender=Tienda)
def add_to_product_list_display(sender, instance, new, **kwargs):
  if new:
  # I don't know how to get the ModelAdmin's instance for a given
class,
  #  but it must be something in django.contrib.admin.site
  product_admin.list_display.append('stock_tienda_{id}'.format(id=
instance.id))

you probably need another listener before .delete of stores, and I'm not
certain the __getattr__ hack will work, but this sounds interesting.

Please try on those lines, and let me know if this worked, I'm most
interested

--
"The whole of Japan is pure invention. There is no such country, there are
no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
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: ManyToMany relationship with intermediate model and admin list display with each realtion with value as diferent column

2012-07-24 Thread Ignacio Soto
ok, it looks very nice i will try and let you know.. thanks

2012/7/24 Tomas Neme 

>
> > as shown in the picture, this i could do by add a method in the model
> > getTienda1 and return the stock and do it for each store, but i want it
> to
> > be created dinamically because the user could create a new store and it
> will
> > not be there.
> >
> > so this is my cuestion: can i do that?
>
> Interesting question. You COULD try the following:
>
> in the ProductAdmin ModelAdmin's class' __init__ you can define
> list_display like
>
> from store.models import Tienda
> for store in Tienda.objects.all():
> self.list_display.append('stock_tienda_{id}'.format(id=store.id))
>
> this would give you the list of existing stores at server init time.
> and then you could define your Product model's __getattr__ method
> something like this:
>
> def __getattr__(self, attr):
>  base = 'stock_tienda_'
>  if attr[:len(base)] == base:
>  return
> Product.objects.filter(tienda=Tienda.objects.get(id=attr[len(base):]))
>  return super(Product, self).__getattr__(self, attr)
>
> this should make the ModelAdmin's hack work
>
> finally, you need a way to add new columns for newly created stores, so
> maybe a post_save signal on Tienda objects
>
> @receiver(post_save, sender=Tienda)
> def add_to_product_list_display(sender, instance, new, **kwargs):
>   if new:
>   # I don't know how to get the ModelAdmin's instance for a given
> class,
>   #  but it must be something in django.contrib.admin.site
>   product_admin.list_display.append('stock_tienda_{id}'.format(id=
> instance.id))
>
> you probably need another listener before .delete of stores, and I'm not
> certain the __getattr__ hack will work, but this sounds interesting.
>
> Please try on those lines, and let me know if this worked, I'm most
> interested
>
> --
> "The whole of Japan is pure invention. There is no such country, there are
> no such people" --Oscar Wilde
>
> |_|0|_|
> |_|_|0|
> |0|0|0|
>
> (\__/)
> (='.'=)This is Bunny. Copy and paste bunny
> (")_(") to help him gain world domination.
>
> --
> 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.
>



-- 
__

Ignacio Soto Reveco
Staff IngeHost

-- 
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: Query Distances from User

2012-07-24 Thread Markus Gattol
You're mistaken if you think only mobile devices support geolocation 
queries; current Chrome for example supports it already

 - info: https://developers.google.com/maps/articles/geolocation
 - test your browser: 
http://hpneo.github.com/gmaps/examples/geolocation.html

-- 
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/-/A22jTtb-BKMJ.
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 make template for startapp and startproyect?

2012-07-24 Thread kase
hello..  i wish make my templates  for  django-admin.py  startproyect and 
startapp  but i dont know how, and i dont find documentation to explain how 
to make it (i find documentation from how to use, but not how to make)

THX!

-- 
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/-/ibUgeiUg_kgJ.
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.



json objects and PUT/GET Requests/Response

2012-07-24 Thread svs
Hello,

I am new to both DJANFGO & REST.
Here is my problem,I have defined CRUD specific to that of MongoDB in my 
Models.py file, now I am trying to pass data to be written into this DB 
using http PUT requests.
1.How  parse json objects in the body of HTTP request ?
2.How to create HTTP put/get request for test purposes with json objects 
through CLI or GUI.

We have client side code(written in PERL) which will actually generate 
these requests but I want to test my server side code independently.

Thanks,
svs

-- 
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/-/CkfqZrQiknMJ.
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: json objects and PUT/GET Requests/Response

2012-07-24 Thread Masklinn

On 2012-07-24, at 21:09 , svs wrote:

> Hello,
> 
> I am new to both DJANFGO & REST.
> Here is my problem,I have defined CRUD specific to that of MongoDB in my 
> Models.py file, now I am trying to pass data to be written into this DB 
> using http PUT requests.
> 1.How  parse json objects in the body of HTTP request ?

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.body

https://docs.djangoproject.com/en/dev/topics/serialization/ or 
http://docs.python.org/library/json.html

> 2.How to create HTTP put/get request for test purposes with json objects 
> through CLI or GUI.

https://docs.djangoproject.com/en/dev/topics/testing/#making-requests
https://docs.djangoproject.com/en/dev/topics/testing/#django.test.client.Client.put
https://docs.djangoproject.com/en/dev/topics/testing/#django.test.client.Client.get

-- 
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: json objects and PUT/GET Requests/Response

2012-07-24 Thread sanket

Hi Svs,

please have a look at django-tastypie 
(https://github.com/toastdriven/django-tastypie). 
it's great for the REST purpose.

Thanks,
sanket


On Tuesday, July 24, 2012 12:09:14 PM UTC-7, svs wrote:
>
> Hello,
>
> I am new to both DJANFGO & REST.
> Here is my problem,I have defined CRUD specific to that of MongoDB in my 
> Models.py file, now I am trying to pass data to be written into this DB 
> using http PUT requests.
> 1.How  parse json objects in the body of HTTP request ?
> 2.How to create HTTP put/get request for test purposes with json objects 
> through CLI or GUI.
>
> We have client side code(written in PERL) which will actually generate 
> these requests but I want to test my server side code independently.
>
> Thanks,
> svs
>

-- 
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/-/g8W3dSJ6mK0J.
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 make template for startapp and startproyect?

2012-07-24 Thread Thomas Lockhart

On 7/24/12 11:24 AM, kase wrote:
hello..  i wish make my templates  for  django-admin.py  startproyect 
and startapp  but i dont know how, and i dont find documentation to 
explain how to make it (i find documentation from how to use, but not 
how to make)
There may be a better way suggested by others, but you can use the 
examples from the tutorial as your starting point.


hth

  - Tom

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-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 make template for startapp and startproyect?

2012-07-24 Thread Kurtis Mullins
Check this post out for some decent tips:
http://stackoverflow.com/questions/5661861/customised-settings-files-using-django-admin-py-startproject

On Tue, Jul 24, 2012 at 4:39 PM, Thomas Lockhart wrote:

> On 7/24/12 11:24 AM, kase wrote:
>
>> hello..  i wish make my templates  for  django-admin.py  startproyect and
>> startapp  but i dont know how, and i dont find documentation to explain how
>> to make it (i find documentation from how to use, but not how to make)
>>
> There may be a better way suggested by others, but you can use the
> examples from the tutorial as your starting point.
>
> hth
>
>   - Tom
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> 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.



Can i use mongodb for product/catalog?

2012-07-24 Thread Paul
I'm developing an application that receives products through product-feeds. 
Now each product will have specific attributes; a t-shirt will for example 
have a size attribute and maybe color, while a bottle of shampoo will have 
an attribute specifying the contents or weight. I could solve this in an 
rdbms using a many to many relation between a products table and an 
attributes (item) table and even an attributes (values) table.

The other day however i was reading about mongodb and now i'm wondering if 
it would be a good idea to put the products (catalog) in a mongodb.

Can anyone with more experience than me :) give any directions how this 
could look like? How can i work with mysql alongside mongodb in django for 
example?

Paul

-- 
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/-/KE5AFOuwO54J.
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: Query Distances from User

2012-07-24 Thread JJ Zolper
I dont believe I said it wasnt supported. Currently I am interested in having 
the user have the flexibility to change and update their location manually so 
they can find results in their area. I dont believe geolocation is the answer 
for that. I have the user input city and state and use WGS84 in lat lon and be 
able to calculate locations across america.

-- 
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/-/v0Rf91mzJeQJ.
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.



Discovering Artists through GeoDjango by referencing my Artists database

2012-07-24 Thread JJ Zolper
I apologize for posting more than once I just wanted to make changes. I 
appreciate the help in advance!

JJ

-- 
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/-/tXPsEMbkQe0J.
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: object has no attribute '_state'

2012-07-24 Thread Blair Trump
Thank you!  Just also had this problem today, 24 July 2012.

Resolved now.  :)

Cheers!

On Thursday, July 12, 2012 10:30:27 AM UTC-7, aria wrote:
>
> Hello, 
>
> I realize this post is from 2010, but I also had this problem as of July 
> 12 2012. It's still one of the first results in a search for the error, so 
> I'm posting for future googlers. 
>
> According to the Django Model 
> reference,
>  
> you should avoid overriding the __init__ method when inheriting from Model, 
> especially if the signature changes. They recommend to instead add a custom 
> manager to handle this. 
>
> On Monday, July 5, 2010 7:51:51 PM UTC-7, jcage wrote:
>>
>> Hi everyone. I'm quite new to python and django. I was wondering if 
>> anyone could shed some light on this topic : 
>>
>> My models.py contains the classes QuestionSet and Question, which 
>> inherits the former. 
>> In the shell, I define a Question object as follows 
>>
>> q1 = Question(script = "How are you?", comment = "no comment", order = 
>> 1) 
>>
>>
>> but an attempt to run q1.save() results in the following error : 
>>
>> >>> q1.save() 
>> Traceback (most recent call last): 
>>   File "", line 1, in  
>>   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
>> python2.6/site-packages/django/db/models/base.py", line 435, in save 
>> self.save_base(using=using, force_insert=force_insert, 
>> force_update=force_update) 
>>   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
>> python2.6/site-packages/django/db/models/base.py", line 447, in 
>> save_base 
>> using = using or router.db_for_write(self.__class__, 
>> instance=self) 
>>   File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ 
>> python2.6/site-packages/django/db/utils.py", line 133, in _route_db 
>> return hints['instance']._state.db or DEFAULT_DB_ALIAS 
>> AttributeError: 'Question' object has no attribute '_state' 
>>
>>
>>
>> The class definitions are : 
>>
>> class QuestionSet(models.Model): 
>> title = models.CharField(max_length=100) 
>> description = models.TextField() 
>> order = models.IntegerField() 
>>
>> def __init__(self, *args, **kwargs): 
>> self.title = kwargs.get('title','Default Title') 
>> self.description = kwargs.get('description', 'DefDescription') 
>> self.order = kwargs.get('order', 0) 
>>
>>
>> class Question(QuestionSet): 
>> script = models.CharField(max_length=200) 
>> comment = models.TextField() 
>>
>>
>> def __init__(self, *args, **kwargs): 
>> QuestionSet.__init__(self, args, kwargs) 
>> self.script = kwargs.get('script', "undefined") 
>> self.comment = kwargs.get('comment', "no comment") 
>>
>>
>>
>>
>> Would greatly appreciate any suggestions
>
>

-- 
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/-/SxjdrS-5MhMJ.
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.



Return SQL calculation within queryset

2012-07-24 Thread jondbaker
I've implemented the spherical law of cosines to aid in proximity-based 
searching. Everything works correctly, but I'm a bit stumped as to how I 
can return the calculated distance for a record given that it's not a field 
in the model. In the Model Manager below, row[1] represents the dynamically 
calculated distance, but I need to find a way to "attach" each calculation 
to it's corresponding record so that I can print the distance in a template.

class LocationManager(models.Manager):
'''
'''
def nearby_locations(self, latitude, longitude, radius):
'''
'''
cursor = connection.cursor()
if settings.DATABASES['default']['ENGINE'] == 
'django.db.backends.sqlite3':
# sqlite doesn't natively support math functions, so add them
connection.connection.create_function('acos', 1, math.acos)
connection.connection.create_function('cos', 1, math.cos)
connection.connection.create_function('radians', 1, 
math.radians)
connection.connection.create_function('sin', 1, math.sin)

sql = """SELECT id, (3959 * acos(cos(radians(%f)) *
  cos(radians(latitude)) * cos(radians(longitude) - 
radians(%f)) +
  sin(radians(%f)) * sin(radians(latitude
  AS distance FROM locations_location
  GROUP BY id HAVING distance < %d
  ORDER BY distance ASC""" % (latitude, longitude, latitude,
  int(radius))
cursor.execute(sql)
data = [(row[0], row[1]) for row in cursor.fetchall()]
ids = [i[0] for i in data]
return self.filter(id__in=ids)

-- 
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/-/pfZSZB1nLVIJ.
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: Discovering Artists through GeoDjango by referencing my Artists database

2012-07-24 Thread JJ Zolper
I also want to point out the reason why I am trying to bring one model into 
another.

MadTrak/
 manage.py
 MadTrak/
Artists/
  manage.py
  Artists/
 initialize/
   models.py
Fans/
  manage.py
  Fans/
Venues/
  manage.py
  Venues/
GeoDjango/
  manage.py
  GeoDjango/
 discover/
   models.py

As you can see I have 5 projects. MadTrak, Artists, Fans, Venues, 
GeoDjango. The idea here is that the top level MadTrak project handles 
everything that has to do with the simple about pages etc. The Artists 
project has the artist database in it and same for Fans and Venues 
respectively. And Finally GeoDjango has discover with is my app to 
hopefully be requested by a Fan and pull data from the Artist database and 
return that to the user.

I have no idea to be honest if this thought process is the correct one 
because I'm not that familiar with databases and how my whole directory 
tree here would interact so the advice you might be able to give could be 
entirely priceless to my whole understand of how to build a website with 
Django.

Without the advice it could break my whole building process.

I believe this all makes sense. I have separated out the major parts. The 
major databases of content Artists, Fans, Venues into their own projects 
with their databases and GeoDjango with its spatial database. I just don't 
have the knowledge to be able to connect the dots between how I can 
ACTUALLY call upon the data in my Artists project database and perform 
operations on it within my GeoDjango project.

Thanks,

JJ

On Tuesday, July 24, 2012 11:48:06 AM UTC-4, JJ Zolper wrote:
>
> Hello fellow Django developers,
>
> So here is my model that interfaces with my Artists database:
>
>
>
> from django.db import models
>
> class Artist(models.Model):
>   name = models.CharField(max_length=30)
>   genre = models.CharField(max_length=30) 
>   city = models.CharField(max_length=30) 
>   state = models.CharField(max_length=30) 
>   country = models.CharField(max_length=30)
>   website = models.UrlField()
>
>   def __unicode__(self):
> return self.name
>
>
>
> Okay now that you see my database backend interface here's where I'm going 
> next.
>
> I've been working with GeoDjango for some time now. I've created an app 
> within my GeoDjango project called "discover". What's my goal? Well, I want 
> this app to be able to return information to my users. This app will take 
> the given parameters such as "locationfrom" (the user of the website 
> inserts their city, state) and then that value is used to bring in the 
> artists in their area in relation to the variable "requesteddistance" 
> (which for example could be 25 mi) along with another variable "genre" (a 
> query on the artists). So the picture is the user might say I want to see 
> all the "Rock" artists "25 mi" from me in "Vienna, VA".
>
> Now that you can see my project here, here is my question.
>
> In my discover app in the models.py file I could use some help. Through 
> this discover app I want to be able to reference the Artists database. As 
> you can see from above the
> models.py file has the fields to establish an Artist and their 
> information. Thus, when a request comes in to the discover app I want to be 
> able to calculate the requested information and return that. Here's where 
> I'm stuck... 
>
> In my mind I feel that the appropriate way to do this is to basically 
> create some sort of ForeignKey in the models.py of discover to the 
> models.py of Artist? That way I don't have to have two databases of the 
> same data but can simply reference the Artist database from the discover 
> app.
>
> Another idea I had was instead of creating a "field" link between the two 
> to try to import the Artist class from the models.py to the models.py file 
> of the discover app? Then from my views.py file in discover I can process 
> the given information referenced and return the result.
>
> Any input is welcome. I am striving to use Django's DRY (Don't Repeat 
> Yourself) methodolgy and try to reference the Artist database and do the 
> actual processing in the discover application.
>
> Thanks a lot for your advice,
>
> JJ Zolper
>
>
>

-- 
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/-/CFzezsCyJQwJ.
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-us

Re: All of the sudden getting TemplateDoesNotExist error

2012-07-24 Thread Karen Tracey
On Tue, Jul 24, 2012 at 11:41 AM, rmschne  wrote:

> I have made no changes to settings.py. Honest.  I'm running Django 1.4.0
> alpha.


Why alpha rather than the released version? Not that I think it has
anything to do with the problem, it just seems odd to stick with an alpha
level after the official release is available.



> The variable TEMPLATE_DIRS is pointing to a folder which exists and the
> template 'directory.html' i wish to load in in that
> folder, /Users/rmschne/Documents/source/django/projects/socmgmt/templates/.
>  My ID has appropriate permissions (running on Mac OS/X).
>
> All of the sudden today (and it worked  a few days ago), I get
> "TemplateDoesNotExist" error.  This happens for any of the templates I try
> to load.
>
> Frankly, I'm at a kinda loss as to where to start debugging this since
> everything looks ok and I don't recall making any changes that would be
> relevants.
>
>
With DEBUG on the template loader post mortem on the debug page should give
some clues.  What does it say?

Karen
-- 
http://tracey.org/kmt/

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



render a models slug field as a url

2012-07-24 Thread Matthew Meyer
Hello all,

I'm trying to load the url of a model created with get_absolute_url() 
programmatically in my view. There are basically three steps I need to 
accomplish this:

1. make sure @permalink is working correctly. This step I am fairly 
confident I have completed. Here is the model I use: 
http://dpaste.org/nH0cZ/

2. make sure I am rendering the url correctly in my view: 
http://dpaste.org/FOGjs/ 

This view is fairly involved. The return statement on line 12 is where I am 
trying to load the url. In a nutshell, if the request is GET this view 
renders a form for the user which they can use to fill some fields in a 
model. one of the fields they fill ("name") I want to use as my the 
rendered url, which is why I am trying to pass {'event': Event} on line 12 
when request.method == 'POST' and the user has submitted the form. Right 
now when the user submits the post, the event_page.hml loads but without 
the event object url.

3. make sure my urlconfs are working:: http://dpaste.org/LPdfK/ Not 
positive here, but I know this is fairly simple to most. I just tried to 
follow what the docs had for get_absolute_url and @permalink (
https://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#django.db.models.permalink)
 
Something is wrong though because the "view on website" button in admin is 
leading to a permalinked url that doesn't match.

As you can see, I am quite a bit lost and could really use some guidance. 
Any help is appreciated. Thanks!

-- 
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/-/w8b_P_KhLPYJ.
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: Query Distances from User

2012-07-24 Thread Markus Gattol
I see. You could use geolocation and still let the user input his location 
manually though even after you got a result via geolocation. The manual 
result via geocoding you can do in various ways like simple 'user puts in 
address, lat/lng is returned' or maybe even 'user drags marker to his 
position on map, lat/lng is returned'. Several ways to do it really. I'd 
however still use geolocation as a first step to aid user comfort and leave 
it to the user to decide whether or not he wants to correct his location if 
necessary/desired.

-- 
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/-/jgAhtvlbIfIJ.
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.



It's that possible to modify context views from middleware?

2012-07-24 Thread yodi aditya

Hi,

Is that posible to make context manipulation (in every views) before 
send to templates from middleware?

I use Django 1.3 at this case.

Eg:
views.py

def view_function:
return render(request, templates, data)

def other_function:
return render(request, templates, data)

Middleware will retrieve this "data" and check if particular object 
classname is exist or not.

If exists, doing some manipulation and pass it to templates.

It more like global views manipulation.
It will manipulate data both view_function and other_function (at this 
case).


Thank you for any response and help

Regards,

@yodiaditya

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