Re: Pango causing mod_wsgi to crash - Segmentation fault (11)
Hi Florian, I have been working on the problem the whole weekend and after trying all the mog_wsgi debugging method I still do not have a solution. I do know that the error does not lie in my django code or my apache configuration as I did the exact setup on a ubuntu machine and it works 100%. It seems to be a problem with GTK2 on debian. What version numbers do you need? ~$ dpkg -l | grep "apache" ii apache22.2.16-6+squeeze4 Apache HTTP Server metapackage ii apache2-mpm-worker 2.2.16-6+squeeze4 Apache HTTP Server - high speed threaded model ii apache2-prefork-dev2.2.16-6+squeeze4 Apache development headers - non-threaded MPM ii apache2-utils 2.2.16-6+squeeze4 utility programs for webservers ii apache2.2-bin 2.2.16-6+squeeze4 Apache HTTP Server common binary files ii apache2.2-common 2.2.16-6+squeeze4 Apache HTTP Server common files ii libapache2-mod-fcgid 1:2.3.6-1an alternative module compat with mod_fastcgi ii libapache2-mod-wsgi3.3-2 Python WSGI adapter module for Apache |~$(127) dpkg -l | grep "gtk" ii libgtk2.0-02.20.1-2 The GTK+ graphical user interface library ii libgtk2.0-bin 2.20.1-2 The programs for the GTK+ graphical user interface library ii libgtk2.0-common 2.20.1-2 Common files for the GTK+ graphical user interface library rc libwxgtk2.8-0 2.8.10.1-3+b1 wxWidgets Cross-platform C++ GUI toolkit (GTK+ runtime) ii python-gtk22.17.0-4 Python bindings for the GTK+ widget set ~$ dpkg -l | grep "python" ii ipython0.10-2 enhanced interactive Python shell ii libgv-python 2.26.3-5 Python bindings for graphviz ii libpython2.6 2.6.6-8+b1 Shared Python runtime library (version 2.6) ii python 2.6.6-3+squeeze6 interactive high-level object-oriented language (default version) ii python-cairo 1.8.8-1+b1 Python bindings for the Cairo vector graphics library ii python-central 0.6.16+nmu1 register and build utility for Python packages ii python-dateutil1.4.1-3 powerful extensions to the standard datetime module rc python-django 1.2.3-3+squeeze1 High-level Python web development framework ii python-flup1.0.2-1 Implements Python Web Server Gateway Interface (WSGI) ii python-genshi 0.6-1 Python XML-based template engine ii python-gobject 2.21.4+is.2.21.3-1 Python bindings for the GObject library ii python-gtk22.17.0-4 Python bindings for the GTK+ widget set ii python-imaging 1.1.7-2 Python Imaging Library ii python-magic 5.04-5 File type determination library using "magic" numbers (Python bindings) rc python-matplotlib-data 0.99.3-1 Python based plotting system (data package) ii python-minimal 2.6.6-3+squeeze6 minimal subset of the Python language (default version) ii python-mysqldb 1.2.2-10+b1 A Python interface to MySQL ii python-numpy 1:1.4.1-5 Numerical Python adds a fast array facility to the Python language ii python-openssl 0.10-1 Python wrapper around the OpenSSL library ii python-pam 0.4.2-12.2 A Python interface to the PAM library ii python-pexpect 2.3-1 Python module for automating interactive applications ii python-pkg-resources 0.6.14-4 Package Discovery and Resource Access using pkg_resources rc python-pygments1.3.1+dfsg-1 syntax highlighting package written in Python ii python-pygraphviz 1.0-1 Python interface to the Graphviz graph layout and visualization package ii python-serial 2.3-1 pyserial - module encapsulating access for the serial port ii python-setuptools 0.6.14-4 Python Distutils Enhancements (setuptools compatibility) rc python-subversion 1.6.12dfsg-6 Python bindings for Subversion ii python-support 1.0.10 automated rebuilding support for Python modules ii python-twisted-bin 10.1.0-3 Event-based framework for internet applications ii python-twisted-core10.1.0-3 Event-based framework for internet applications ii python-twisted-names 10.1.0-1 A DNS protocol implementation with client and server ii python-twisted-web 10.1.0-1 An HTTP protocol implementation together with clients and servers ii python-webpy 1:0.34-2 Web framework for Python
Pango causing mod_wsgi to crash - Segmentation fault (11)
Hi I was wondering if anyone had a similar problem when trying to use pango in django running under mod_wsgi on apache. I am running |20:11:06|# cat /etc/debian_version 6.0.3 When I run a runserver on the same server it works fine but the moment I "import pango" in any of my modules the mod_wsgi apache server raises a 500 error. I did the whole installation using apt-get and installed pygtk. I would appreciate any help to try and debug this issue. The only thing in my apache error.log is : child pid 3642 exit signal Segmentation fault (11) 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.
Pango causing mod_msgi to crash - Segmentation fault (11)
Hi I was wondering if anyone had a similar problem when trying to use pango in django running under mod_wsgi on apache. I am running |20:11:06|# cat /etc/debian_version 6.0.3 When I run a runserver on the same server it works fine but the moment I "import pango" in any of my modules the mod_wsgi apache server raises a 500 error. I did the whole installation using apt-get and installed pygtk. I would appreciate any help to try and debug this issue. The only thing in my apache error.log is : child pid 3642 exit signal Segmentation fault (11) Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Getting a class using a variable name.
Ok, I found a way. I don't know if it's the best way but it works :) return getattr(__import__(module_name, fromlist = [class_name]), class_name) Thanks for the help. -- 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: Getting a class using a variable name.
Hi Martin, Thanks for the tip. The thing is that I store my class names in the database. So class B(models.Mode): form_class = models.CharField(...) def get_form_class(self): return ..(self.form_class) <- this is where I need to some how get the class object from a different file. I know I could use globals()[self.form_class] if the class was in the same file but the classes are in various modules. -- 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: Getting a class using a variable name.
I should add that in the B class function get_a_class I only have a variable name "A" -- 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.
Getting a class using a variable name.
Hi, I have been struggling with this for a while now and I can't seem to find a way of returning a class object from a different module without importing it. Say I have two files: test_a.py class A(models.Model): pass test_b.py class B(models.Model): def get_a_class(self): return ? to get the A class from test_a.py I do not want to import it as it will cause circular references. Thank you -- 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: Get child model class
Ok this solution worked for me :):) {{{ from django.db import models from django.contrib.contenttypes.models import ContentType from django.db.models.query import QuerySet class SubclassingQuerySet(QuerySet): def __getitem__(self, k): result = super(SubclassingQuerySet, self).__getitem__(k) if isinstance(result, models.Model) : return result.as_leaf_class() else : return result def __iter__(self): for item in super(SubclassingQuerySet, self).__iter__(): yield item.as_leaf_class() class CFManager(models.Manager): def get_query_set(self): return SubclassingQuerySet(self.model) class CF(models.Model): type = models.CharField(max_length = 40) content_type = models.ForeignKey(ContentType,editable=False,null=True) objects = CFManager() def save(self, *args, **kwargs): if(not self.content_type): self.content_type = ContentType.objects.get_for_model(self.__class__) super(CF, self).save(*args, **kwargs) def as_leaf_class(self): content_type = self.content_type model = content_type.model_class() if (model == CF): return self return model.objects.get(id=self.id) class CFT(CF): data = models.CharField(max_length=20) objects = CFManager() class CFI(CF): data = models.IntegerField() objects = CFManager() class Doc(models.Model): name = models.CharField(max_length = 40) cf = models.ManyToManyField(CF, null = True) }}} now when I do: In [12]: doc.cf.all() Out[12]: [, ] Thanks for all the suggestions and help. -- 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: Get child model class
this is more or less what I found. I will have to see how I can implement it on my side. http://djangosnippets.org/snippets/1037/ -- 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: Get child model class
Thank you, this is more or less what I am looking for. I don't however want to make the CF class an abstract class as I want to have some common fields in there. The Idea behind this is that I want to store custom fields (CF) for various models that a user will be defining themselves. I do not want to keep the data in a single table as I want to be able to filter and do database actions on specific field types. But in order recreate a dynamic form from all the CF fields belonging to a document (Doc) I want to be able to iterate over Doc.cf.all() and add the specific CF field type to a form. I hope that makes sense :) -- 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: Get child model class
Just to clarify your suggestion In [100]: isinstance(x, CFT) Out[100]: False In [101]: isinstance(x, CFI) Out[101]: False In [105]: isinstance(e, CF) Out[105]: True This is not what I am looking for. I want to know to what class the CF primary key points to. So if it's CFT or CFI -- 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: Get child model class
I now the isinstance function but that will return the CF class. I want to know the child class of CF for that specific primary key. On May 6, 9:30 pm, Shawn Milochikwrote: > This might work: > > http://docs.python.org/library/functions.html#isinstance -- 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.
Get child model class
Hi, I am not sure if this is possible but it would really help if it is. I have 4 classes class CF(models.Model): class CFT(CF): data = models.CharField(max_length=20) class CFI(CF): data = models.IntegerField() class Doc(models.Model): name = models.CharField(max_length = 40) cf = models.ManyToManyField(CF, null = True) I create a new Doc doc = Doc(name = 'x') doc.save() I create a new record for CFT and CFI cft = CFT(data = 'y') cft.save() cfi = CFI(data = 1) cfi.save() now I add them to the doc manytomany table doc.add(cft) doc.add(cfi) now if I get any of the manytomany fields from doc x = doc.cf.all()[0] how can I find out if x is an instance of CFT or CFI -- 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: Check all foreign keys before delete.
Great thanks, will definitely have a look. -- 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: Check all foreign keys before delete.
Hit the nail on the head :) Thank you very much for the quick response. Problem solved. -- 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.
Check all foreign keys before delete.
Hi, I am constantly running in a brick wall when it comes to deleting records in Django. If you have one or two foreign keys it is easy to check if they are in use, but once an application starts getting big you can not remember which models are making use of a foreign key and if a specific foreign key is in use. So my question: Is there a way to check if a single model record if being used as a foreign key in all the models in a django project? For example: class Stage(models.Model): description = mo. class Document(models,Model): stage = models.ForeignKey(Stage) class Server(models.Model): stage = models.ForeignKey(Stage) Now when I do "stage = Stage.objects.get(pk=x)" is it possible for me to do some like "stage.?" and get back true or false if "stage" is being used either in Document or Server or any other class that uses Stage as a foreign Key but also only for this 1 specific record. All I really want to do is see if I can delete "stage" without it effecting and other records in the database. Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Queryset from 2 models with second model filtered.
Typically I simply want to do a left join but have it as an object in django rather than a sql raw query. The queryset would look like. Select a.code as 'product_code', a.description as 'product_description', b.code as 'customer_code', b.code as 'customer_description', ifnull(b.code, a.code) as 'code', ifnull(b.description, b.description) as 'description' from products a left join customerproduct b on b.product_id = a.id where b.customer_id = 'X' I know I could create a view in sql and create a model for that but I am sure there must be a nicer solution. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Queryset from 2 models with second model filtered.
Hi, I have a tricky one, I don't have an error but rather trying to avoid many database hits. I am trying to build a product database which can have different field values per customer. So the model would look something like this. class Customer(models.Model): name = models.CharField(max_length = 50) class Product(models.Model): code = models.CharField(max_length = 32) description = models.CharField(max_length = 50) class CustomerProduct(models.Model): product = models.ForeignKey(Product) customer = models.ForeignKey(Customer) code = models.CharField(max_length = 32, null = True, blank = True) description = models.CharField(max_length = 50, null = True, blank = True) The CustomerProduct will only have an entry if a code or description is provided for a customer. Now ideally I would like to pull a queryset for a customer which lists all available products (Product), but if it finds that a CustomerProduct exists that it returns the CustomerProduct code and description instead of the Product code and description. Even better would be having a queryset filtered by Customer that I could have as 1 object and call the field values like x.product.code and x.customerproduct.code. Just looking for some suggestions. 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-us...@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: Middleware for models
Ok, I think I have sorted out my queryset problem, I wrote a custom manager: class UserBranchModelManager(models.Manager): def for_request(self, request): if settings.DO_BRANCH_FILTER: return super(UserBranchModelManager, self).get_query_set().filter(branch__pk = request.userBranchID) return super(UserBranchModelManager, self).get_query_set() class Amodel(models.Model): branch_filter = UserBranchModelManager() def aview(request) queryset.= Amodel.branch_filter.for_request(request) Thanks Shawn for directing me in the right direction. Now I just need to override the get() method. :) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: can't authenticate in template
Just as a suggestion, if you don't need to customize the get_user() method then simply don't have a get_user() method in your custom authentication class. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Middleware for models
Sorry one more thing, the above filters my querysets but then comes the get() method on each model. I use urls with pk's so a user could just try to change the url to a pk that does not belong to them and view it. To filter this out I run yet another function: def relation_branch_validation(request, relation): if settings.DO_BRANCH_FILTER: if relation.branch.id != request.userBranchID: raise InvalidBranchException('%s is requesting data for relation %s. Request from %s' % (request.user.username, unicode(relation), request.view_name)) def aview(request, obj_id): relation = get_object_or_404(Relation, pk = obj_id) relation_branch_validation(request, relation) This is really no fun adding these functions to each view and I tell you there is a lot of views. :) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Middleware for models
Just so you have an idea what I am trying to do. :) I have a custom middleware that adds a userBranchID variable to each request according to the users branch in the User model. Now in each view when I use any queryset I have to do the following: def filter_branch(request, queryset): if settings.DO_BRANCH_FILTER: queryset = queryset.filter(branch__pk = request.userBranchID) return queryset def aview(request): queryset = Model.objects.all() queryset = filter_branch(request, queryset) I would like to avoid running the filter_branch function each time I run a queryset. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Middleware for models
Hi Shawn, I use Managers often to limit my querysets and add additional fields that I want dynamically calculated using sql. I just don't see how I can get the request object to the models.Manager so it knows what to filter by (user.uid). :( I know I could do a filter in each view queryset.objects.filter(branch__user = request.user) but I don't like this method because I might just forget to add the filter and all data will be visible. Karol -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: can't authenticate in template
On Feb 13, 2:23 am, paul <phart...@gmail.com> wrote: > On Feb 12, 5:03 pm, pbzRPA <pbz...@gmail.com> wrote: > > > The middleware looks good. Is your browser maybe not blocking cookies? > > I have really though hard about it, but without code it's really > > difficult to get a picture of where the problem may lie. You also said > > you do custom authentication, then why is it that you printing out the > > request in the django.contrib,auth.views.login? > > In settings.py, I also have: > > AUTHENTICATION_BACKENDS = ('auth.backends.ldap_backend',) > > The following code represents the backend that authenticates against a > LDAP directory. It is working correctly (if the supplied username and > password match, it returns a User -- I've verified this. I'm trying > to not overflow this message with code, hopefully I'm including enough > code to be informative. So basically my understanding is that if I > want to use a different authentication backend, I just specify it > under AUTHENTICATION BACKENDS, and Django will abstract the > authentication and login process as long as my authentication backend > returns a User instance if an entered username and password are > validated. Please see the following code, I'll add some more comments > after it: > > class ldap_backend(ModelBackend): > def authenticate(self, username=None, password=None): > if username is not None and password is not None: > > > if valid: # valid = True if username & password matched > the LDAP entry > return self.get_user(username) > > def get_user(self, username): > try: > return User.objects.get(username=username) > except User.DoesNotExist: > return None > > The following is a portion of the django.contrib.auth.login function. > If I supply the correct username and password, the function executes > all the way to returning HttpResponseRedirect. I am showing where I > put in a print statement to show request.user.is_authenticated(). > This prints "True". > > def login(request, template_name='registration/login.html', > redirect_field_name=REDIRECT_FIELD_NAME): > "Displays the login form and handles the login action." > redirect_to = request.REQUEST.get(redirect_field_name, '') > if request.method == "POST": > > print "end %s" % request.user.is_authenticated() # will > be True if username & pw are validated > return HttpResponseRedirect(redirect_to) > > Now, here is the code of the view that handles redirect_to: > > view.py > def home(request): > context = {'title_prefix' : 'Account Home'} > template = 'accounts/home.html' > rc = RequestContext(request) > return render_to_response(template, context, context_instance=rc) > > In this code, if I check request.user.is_authenticated, it returns > False. request.user is actually AnonymousUser. However, if I look at > request.session.items, I see the correct _auth_user_id for the user > that just logged in. > > I hope that my code might be helpful. I'm quite perplexed about > what's wrong. > > thanks again, > > Paul Hi Paul, I wonder if your problem does not lie in your "get_user" method in your ldap_backend. The normal get_user method requires a used_id and not a username. The authentication method should return it's own user instead of calling get get_user method. Try changing you get_user method to: def get_user(self, user_id): try: return User.objects.get(pk=user_id) except User.DoesNotExist: return None and in your authenticate method replace: """return self.get_user(username) """ with: try: user = User.objects.get(username=username) except User.DoesNotExist: return None return user I think that django calls the get_user method with a request. The django auth calls " user = backend.get_user(user_id) or AnonymousUser()" Hope that helps. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: can't authenticate in template
The middleware looks good. Is your browser maybe not blocking cookies? I have really though hard about it, but without code it's really difficult to get a picture of where the problem may lie. You also said you do custom authentication, then why is it that you printing out the request in the django.contrib,auth.views.login? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: can't authenticate in template
Can you please add a dump of your MIDDLEWARE_CLASSES as it is in your settings file. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: can't authenticate in template
It's going to be difficult to help you out if you using a custom authentication. Take a look at this comment from the django site and tell me if you following these rules in your custom authentication. """ Calling authenticate() first When you're manually logging a user in, you must call authenticate() before you call login(). authenticate() sets an attribute on the User noting which authentication backend successfully authenticated that user (see the backends documentation for details), and this information is needed later during the login process. """ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Middleware for models
Hi, I don't actually have a problem but rather a need for a suggestion. I am building a web application and in order to demo the site on one database I have a need to secure the data for each user. I have a field in each model that is a foreign key to a unique field on the User model. The tricky part is that it's becoming a lot of maintenance to check in each view if the record was created by the user or not. I wrote a normal middleware that adds the users unique site to the request. This helps with having the user site in each view but I was wondering how I could get the user site into a model so that each time a user calls a model or saves a model it validates that it was created by that user. Ideally I would like to get the users site into a ModelManager and limit the queryset there and have the users site available in the save method of a model. I do not want to add the users site to the session as it's easy to manipulate a session variable. Is there any form of middleware for models so that you can pass the request object to it? Any advice will be highly appreciated. Regards -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Filter queryset by foreignkey or manytomany count
Hi Does anyone know if its possible to filter a queryset by the count of it's foreignkey or manytomany set? For example: class Y(models.Model): name = models.CharField(...) class X(models.Model): name = models.CharField(...) y_rec = models.ManyToManyField(Y) class Z(models.Model): x = models.ForeignKey(X) now I would like to: X.objects.filter(z__count__gt = 0, y__count = 0) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Filtering queryset using two fields in one model
Excellent thank you. So the solution is: from django.db.models import F X.objects.filter(id = F('new_id')) Thanks for the help guys. On 8 Gru, 19:38, Boris Schäling <bo...@highscore.de> wrote: > > -Original Message- > > From: django-users+ow...@googlegroups.com [mailto:django- > > users+ow...@googlegroups.com] On Behalf Of pbzRPA > > Sent: Tuesday, December 08, 2009 7:19 PM > > To: Django users > > Subject: Filtering queryset using two fields in one model > > > Hi, > > > I am not sure if this is a really stupid question but how can you > > filter a model by comparing two of it's own fields? > > > for example: > > > class X(models.Model): > > id = models.IntegerField() > > new_id = models.IntegerField() > > > now I want to say X.objects.filter(id = new_id) > > Seehttp://docs.djangoproject.com/en/dev/topics/db/queries/#filters-can-r... > e-fields-on-the-model > > What is missing though is a feature to put a literal value on the left hand > side - for example: > > X.objects.filter(1 = id) > > (Here for the equality operator it doesn't matter of course.) > > Boris -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Filtering queryset using two fields in one model
Hi, I am not sure if this is a really stupid question but how can you filter a model by comparing two of it's own fields? for example: class X(models.Model): id = models.IntegerField() new_id = models.IntegerField() now I want to say X.objects.filter(id = new_id) 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-us...@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: Filtering on model methods
Thank you for your help. I guess I will have to create temp table etc and do it that way. It's a pity django does not provide this kind of functionality. --~--~-~--~~~---~--~~ 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: Filtering on model methods
I think my problem is both 1 and 2. What happens when you want to use python modules to analyse the extra field? For Example: Database table History: id | Ordered | Delivered | Invoiced | 1 10 15 5 2 553 class History(models.Model): ordered = models.IntegerField() delivered = models.IntegerField() Invoiced = models.IntegerField() def compute_problem(self): 'here will be code that analyses the above data' if self.ordered > self.delivered: return self.ordered - self.delivered if self.invoiced < self.delivered: return self.delivered - self.invoiced return 0 Ideally I would like to create the virtual scenario: id | Ordered | Delivered | Invoiced | compute_problem 1 10 15 5 -5 2 553 -2 in the view I would like to do the following. Please note that my compute_problem is a real basic example and I am sure that the above example I could do in SQL but my methods become a lot more complicated. queryset = History.objects.filter().exclude(compute_problem = 0) I can not modify the database as I am writing add-ons and not creating the database myself. I hope this makes a bit more sense. :) --~--~-~--~~~---~--~~ 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: Filtering on model methods
Thanks for you reply Mikhail, I do use model managers but more often to get a certain defined queryset back. Could you maybe show me a simple example of how to implement your suggestion? I imagine it looking something like this. class PersonManager(models.Manager): def get_query_set(self): ??? x = 1 return super(type(self), self).get_query_set() class Person(models.Model): name = models.CharField(...) objects = models.Manager() compare_to_other = PersonManager() Now without pulling the value out of the SQL database how do I add a value? The ?? is where I am not sure of how to define a variable per sql line. --~--~-~--~~~---~--~~ 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: Filtering on model methods
Sorry I would also like to add that I would like to sort by this field in generic views. So results = Person.objects.filter (compare_to_others__gte = 1).order_by('compare_to_others') --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Filtering on model methods
Hi all, I keep running into a problem. Often when creating models for existing databases which you can not modify, I find myself in need of quite a few model methods. That all works fine but then when I run a view I would like to be able to use the object mapper to filter by the method on a model. In other word often I need a virtual database field that gets calculated on the fly. I know I could just modify the queryset but what if I have thousands and thousands of data to analyse and just need a few results. For example: class Person(models.Model): name = models.CharField(...) def compare_to_other(self): code. return X now in a view I would like to be able to: results = Person.objects.filter(compare_to_others__gte = 1) I am not sure if I am just using bad practice that I run into this problem or not. I hope someone can point me in the right direction. I do not want to use custom sql and often the analysis is too complicated for Sql Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: data too long in a CharField column
Hi, I am not sure if truncating the data is a good solution as the user will be under the impression that all the text was saved whereas only the first 255 was really saved. You can add a max_length to your form or modelform field which will block the user from typing more then the max length. regards. --~--~-~--~~~---~--~~ 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: Custom SQL with a variable issue.
Hi, Could you provide the code of your model and why you would want to use a custom sql instead of the django model object. Regards Pbzrpa --~--~-~--~~~---~--~~ 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 do I set a foreign key as a primary key?
On May 4, 3:07 pm, pbzRPA <pbz...@gmail.com> wrote: > On May 3, 6:52 pm, Malcolm Tredinnick <malc...@pointy-stick.com> > wrote: > > > > > On Sun, 2009-05-03 at 09:03 -0700, Thierry wrote: > > > I have the following model: > > > > class Person(models.Model): > > > person = models.ForeignKey(User) > > > age = models.IntegerField() > > > > How can I set the above foreign key to be my primary key so that my > > > Person table only contains two columns (person, age)? > > > The same way you set any other model field to be a primary key. Have a > > look at the model fields documentation for the common options for all > > fields:http://docs.djangoproject.com/en/dev/ref/models/fields/#ref-models-fi... > > > Regards, > > Malcolm > > class Person(models.Model): > person = models.ForeignKey(User, primary_key = True) > age = models.IntegerField() You should also use the "db_column" option so that the model does not look for a "person_id" field. class Person(models.Model): person = models.ForeignKey(User, primary_key = True, db_column = 'person') age = models.IntegerField() Regards Pbzrpa --~--~-~--~~~---~--~~ 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 do I set a foreign key as a primary key?
On May 3, 6:52 pm, Malcolm Tredinnickwrote: > On Sun, 2009-05-03 at 09:03 -0700, Thierry wrote: > > I have the following model: > > > class Person(models.Model): > > person = models.ForeignKey(User) > > age = models.IntegerField() > > > How can I set the above foreign key to be my primary key so that my > > Person table only contains two columns (person, age)? > > The same way you set any other model field to be a primary key. Have a > look at the model fields documentation for the common options for all > fields:http://docs.djangoproject.com/en/dev/ref/models/fields/#ref-models-fi... > > Regards, > Malcolm class Person(models.Model): person = models.ForeignKey(User, primary_key = True) age = models.IntegerField() --~--~-~--~~~---~--~~ 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 handle view/url situation (Newbie)
On May 4, 1:24 pm, Masklinn <maskl...@masklinn.net> wrote: > On 4 May 2009, at 12:47 , pbzRPA wrote: > > > I would do the following. > > > from django.http import HttpResponseRedirect > > from django.core.urlresolvers import reverse > > > def deleteItems(request, item): > > > return HttpResponseRedirect(reverse('app.views.showItems')) > > FWIW the `'app.views.showItems'` isn't even necessary, you can just > pass the view function and reverse will figure out the rest, so > > return HttpResponseRedirect(reverse(showItems)) > > is, in fact, sufficient. That is correct but only if the function resides in the same file that the reverse function is used. --~--~-~--~~~---~--~~ 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 handle view/url situation (Newbie)
I would do the following. from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse def deleteItems(request, item): return HttpResponseRedirect(reverse('app.views.showItems')) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Django custom operators DB Backend
I would like to know if anyone knows how to create custom operators for querysets. Currently you can do something like: foo.objects.filter(myfield__icontains = x) I would like to add my own operator so I can do something like: foo.objects.filter(myfield__converttext = x) where "converttext" would be my own operator. Currently there a few operators in the django/db/backends/mysql/base.py: operators = { 'exact': '= %s', 'iexact': 'LIKE %s', 'contains': 'LIKE BINARY %s', 'icontains': 'LIKE %s', 'regex': 'REGEXP BINARY %s', 'iregex': 'REGEXP %s', 'gt': '> %s', 'gte': '>= %s', 'lt': '< %s', 'lte': '<= %s', 'startswith': 'LIKE BINARY %s', 'endswith': 'LIKE BINARY %s', 'istartswith': 'LIKE %s', 'iendswith': 'LIKE %s', } I would like to add to this dict without modifying the django code. Any help would be appreciated. --~--~-~--~~~---~--~~ 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: Pyexcelerator VLOOKUP can't parse formula
Found a solution for my problem. There is a patch that you can download so that you can reference other worksheets. https://sourceforge.net/tracker/index.php?func=detail=1687510_id=134081=730645 Hope it helps. PB --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Pyexcelerator VLOOKUP can't parse formula
Good day, I am getting an error when trying to parse a VLOOKUP formula to Excel. ws1.write(row_num, 8, Formula("VLOOKUP(G2;Discounts!A2:B28;2;0)")) It seems to have a problem with the exclamation mark. Any hint would help. Thank You PB --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---