Re: Models: Referencing A Model In Another App and Different Project

2012-07-29 Thread JJ Zolper
"As a general remark related to the issues that JJ has described... are 
there perhaps - or rather, should there be - pointers from the Django site 
that discuss some good practices to the overall approach of designing and 
building sites/projects/apps/databases - as opposed to the technical 
nitty-gritty of mode/view/form construction?"

I second this motion!

"It seems there are an increasing number of "newbies" flocking to Django, 
with perhaps little or no background in CS fundamentals, and guidelines 
like these would be a good place to point them at!"

As far as web programming goes I would say that yes I am a newbie even 
though I am a Computer Engineer at Virginia Tech. More documentation on 
this topic would be grand! Thank you Derek for the comment!



On Sunday, July 29, 2012 3:24:29 AM UTC-4, Derek wrote:
>
> As a general remark related to the issues that JJ has described... are 
> there perhaps - or rather, should there be - pointers from the Django site 
> that discuss some good practices to the overall approach of designing and 
> building sites/projects/apps/databases - as opposed to the technical 
> nitty-gritty of mode/view/form construction?
>
> It seems there are an increasing number of "newbies" flocking to Django, 
> with perhaps little or no background in CS fundamentals, and guidelines 
> like these would be a good place to point them at!
>
>
> On Thursday, 26 July 2012 03:12:09 UTC+2, 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/-/CX4UbSGdzHIJ.
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: Models: Referencing A Model In Another App and Different Project

2012-07-29 Thread Derek
As a general remark related to the issues that JJ has described... are 
there perhaps - or rather, should there be - pointers from the Django site 
that discuss some good practices to the overall approach of designing and 
building sites/projects/apps/databases - as opposed to the technical 
nitty-gritty of mode/view/form construction?

It seems there are an increasing number of "newbies" flocking to Django, 
with perhaps little or no background in CS fundamentals, and guidelines 
like these would be a good place to point them at!


On Thursday, 26 July 2012 03:12:09 UTC+2, 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/-/Yj1aeD50hX0J.
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: Models: Referencing A Model In Another App and Different Project

2012-07-28 Thread JJ Zolper
Okay well atleast im learning from my mistake!

The reason I thought multiple projects was needed was because in each settings 
file I was tied to a database and i felt I need 5 databases. But it seems clear 
that i dont need that many projects.

When you said "you should allocate webserver locations to these projects rather 
then 
start nesting projects" what do you mean?

Yes exactly because its called mysite thats a sign that i should ony have one 
project! Yep.

Yes i believe the sub projects are more of apps that tie to a table in one big 
database.

So when you said "This is probably a lack in the documentation as well, but 
normally you'd 
handle stuff like static pages and the home page in the top-level 
project's inner directory or even bypass django completely by grabbing 
the urls in the webserver and serving static html. 

Views for the MadTrak project should be in: 
MadTrak/ 
        settings.py 
        views.py "

You mean

MadTrak/ 
        settings.py 
        views.py
   about
   models.py
static/
   css/
  Web.css
templates
   Index.html

??

OR do you mean

MadTrak/ 
        manage.py 
        views.py
MadTrak/
   settings.py
static/
   css/
  Web.css
about
   models.py
templates
   Index.html

???

"I think you should start by answering /why/ you need separate databases 
for this. If you have no clear reason, then that's your answer: you 
don't need separate databases. While a model corresponds to a table, a 
collection of models /does not/ correspond to a database."

Yes i asked myself that question and i dont think i need seperate databases 
just simply put multiple models that correspond to multiple tables in one 
database.

When you said "Also, the geodjango database drivers are not specifically for 
spatial 
databases. And similarly spatial databases can contain tables (and thus 
django models) that have no geometric fields. So - it is possible to use 
all your applications in a spatially enabled database with the spatially 
enabled database driver. "

It really opened my eyes. It really did. Youre help is the type that will 
change my web building skills forever and im grateful to you for that. I can 
use the same database for good and enable it as spatial and use it for all my 
applications!

Another thing. In a geodjango project my settings file looked like this:

Database: django.contrib.gis.db

Or whatever i forget exactly but in regular ones its

Database: psycopg_postgresql

Like my question is in my settings file for my solo project what do i put to 
have a spatially enabled django database but also have the postgresql. Im sure 
its simple but how do i " it is possible to use 
all your applications in a spatially enabled database with the spatially 
enabled database driver" ??
Database: 

-- 
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/-/cHVGgxYHrfsJ.
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: Models: Referencing A Model In Another App and Different Project

2012-07-27 Thread Melvyn Sopacua
On 27-7-2012 6:17, JJ Zolper wrote:
> You are probably right to be honest. I might be overdoing it with 
> seperating things apart. I guess sometimes I'm too efficient!
> 
> Here's some more to chew on though:
> 
> 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.

Erm, this is a clear example of how to not do things. A project in it's
simplest form should correspond to one site, so a virtual host or full
fledged server. More complex sites can handle multiple projects, however
you should allocate webserver locations to these projects rather then
start nesting projects. The documentation should perhaps mention this
explicitly, though the fact that the tutorial calls the project 'mysite'
should be a hint.

Aside from that, I see no reasons that these sub-projects as you call
them are in fact projects rather than applications.

> The idea here is that the top level MadTrak project handles 
> everything that has to do with the simple about pages etc.

This is probably a lack in the documentation as well, but normally you'd
handle stuff like static pages and the home page in the top-level
project's inner directory or even bypass django completely by grabbing
the urls in the webserver and serving static html.

Views for the MadTrak project should be in:
MadTrak/
settings.py
views.py

> The Artists 
> project has the artist database in it and same for Fans and Venues 
> respectively.

I think you should start by answering /why/ you need separate databases
for this. If you have no clear reason, then that's your answer: you
don't need separate databases. While a model corresponds to a table, a
collection of models /does not/ correspond to a database. In fact, you
can run several projects using one single database - it makes no
difference to django or the database.
Also, the geodjango database drivers are not specifically for spatial
databases. And similarly spatial databases can contain tables (and thus
django models) that have no geometric fields. So - it is possible to use
all your applications in a spatially enabled database with the spatially
enabled database driver.
-- 
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: Models: Referencing A Model In Another App and Different Project

2012-07-26 Thread JJ Zolper
You are probably right to be honest. I might be overdoing it with 
seperating things apart. I guess sometimes I'm too efficient!

Here's some more to chew on though:

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.

TO MICHAEL: Question 1 & 2. I don't really have to do it this way probably. 
I could place the code in the same artist project most likely. I might just 
be slightly naive right now when it comes to when to use a "project" and 
when to just break it down into code. The reason I wanted to connect is 
because that I have that separate GeoDjango project just for doing 
geographic type work and that is not in the same project space as Artist 
yet I want to do geographic work with the Artist database so I can return 
data based on the artist. Does that make sense?

Question 3. I probably should but I don't quite feel like I know how to yet.

And Conclusion for Michael: Combining the two sounds better everyday to be 
honest. It might be my best solution. So now that you see my directory tree 
might you be able to give me some advice how to attack this problem? Should 
I put my GeoDjango project in the Artist project? If it makes sense what 
I'm doing (Querying the Artist database in the Artist project with the 
GeoDjango cod) then what do you reccomend I do?

Thanks,

JJ

On Thursday, July 26, 2012 9:14:08 AM UTC-4, (unknown) wrote:
>
> I'm not sure whether there is a good solution for this problem with the 
> prerequisites you mentioned. 
> Just because you import onde model doesn't mean you have full access to 
> the 
> underlying database of another project. 
>
> If nobody comes up with a better idea (I never tried something similar), 
> here 
> is what I think: 
>
> Do you really have to do it this way? Why do you need the connecting link 
> on 
> the model layer? 
> How about creating an interface to query the Artist app? (REST or 
> whatever) 
>
> I'd either do that (REST), or I'd combine these two applications into one 
> project. 
>
> good luck, 
>
> Michael 
>
>
> -Original Message- 
> From: django-users@googlegroups.com on behalf of JJ Zolper 
> Sent: Thu 7/26/2012 3:12 AM 
> To: django-users@googlegroups.com 
> Subject: Models: Referencing A Model In Another App and Different Project 
>   
> 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 

RE: Models: Referencing A Model In Another App and Different Project

2012-07-26 Thread michael.pimmer.ext
I'm not sure whether there is a good solution for this problem with the
prerequisites you mentioned.
Just because you import onde model doesn't mean you have full access to the
underlying database of another project.

If nobody comes up with a better idea (I never tried something similar), here
is what I think:

Do you really have to do it this way? Why do you need the connecting link on
the model layer?
How about creating an interface to query the Artist app? (REST or whatever)

I'd either do that (REST), or I'd combine these two applications into one
project.

good luck,

Michael


-Original Message-
From: django-users@googlegroups.com on behalf of JJ Zolper
Sent: Thu 7/26/2012 3:12 AM
To: django-users@googlegroups.com
Subject: Models: Referencing A Model In Another App and Different Project
 
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/-/uypkc91fB9AJ.
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.

<>