RE: Models: Referencing A Model In Another App and Different Project
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. <>
RE: Limiting choices for ModelForm's ForeignKey/ManyToMany
> I'm not sure if this will work, as the ModelForm's QuerySet for the choiceField cannot be changed dynamically during runtime, or can it? You can change the queryset directly in the view: http://stackoverflow.com/questions/291945/how-do-i-filter-foreignkey-choices- in-a-django-modelform Altough having this stored in the model would be more elegant in your case, perhaps anyone else has knows more.. Michael -Original Message- From: django-users@googlegroups.com on behalf of Kevin Sent: Wed 1/4/2012 8:07 AM To: Django users Subject: Limiting choices for ModelForm's ForeignKey/ManyToMany Hello, I have many models which have a foreign key to a main model. Eg: class MainModel: .. .. class VariousModels: main = ForeignKey(MainModel) .. .. Now, these VariousModels sometimes have links to each other in the form of ForeignKey or ManyToMany. I need to limit these ForeignKey and ManyToMany in various ModelForms to only display other VariousModels which share the same MainModel in common. Here is what I tried to do and it didn't work: item = models.ForeignKey(Item, limit_choices_to={'main__pk':main}, blank=True, null=True) I attempted different versions of this on the actual model. I am now looking into how I can perform this using a ModelForm instead of placing the limits on the actual model. I'm not sure if this will work, as the ModelForm's QuerySet for the choiceField cannot be changed dynamically during runtime, or can it? Basically, I am creating a multi-user/multi-section application. The main model described above is a section which a user creates and manages. The user should only see choices in the forms for objects associated with the current section they are editing. Perhaps I am going about this entirely wrong and this should be implemented in a different form, such as a permission. Any ideas on how this can be done would be very helpful, thanks. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en. -- 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. <>
Profiling Django
The django application I am working on is very slow on the server-side, and I want to know why. The essence is to identify which code-parts of processing one request take most time. The app runs with mod_wsgi on Apache, here is what I tried: - django-timelog: the information logged is too unspecific and high-leveled. I want to know which functions and parts of a view require most time. (moreover, analyze_timelog doesn't work here) - django-debug-toolbar with profiling from http://backslashn.com/post/505601626/ - too fine-grained: I do not want to know that 138752 calls to python2.6/posixpath.py:129(islink) take 0.858 seconds. I want to know in which views / functions it happens. - profiling with wsgiref, like described in https://code.djangoproject.com/wiki/ProfilingDjango#no1 - looks like (and probably is?) exactly the same output as the django-debug-toolbar with profiling: too fine-grained, I want to get an overview, not the pure low-level calls. What is your preferred way to analyze/profile the performance of django-applications? thanks, Michael -- 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.