Re: Multiple managers for reverse-links between subclasses
On Jan 21, 11:14 am, Aneurin Pricewrote: > (Apologies for the vague subject; I couldn't think how to summarise this :P) > > Hello all, > > I have an application where some models are inherited from others, like so: > Foo > / \ > Bar Baz > Each object has (or may have) a parent object, which is a Foo (it might be a > Bar > or a Baz, or some other subclass, but it's definitely a Foo). I'd like to be > able to find the children of an object, both overall and by subclass, using > 'foo_object.children.all()', or 'foo_object.bars.all()' and so on. > > Originally I set up parent links in Foo, as something like > "parent=models.ForeignKey('self', related_name='children')", but when I > realised > that I mostly want to get the children in groups, I changed the way I was > doing > this. Now I have per-class links like "parent=models.ForeignKey('Foo', > related_name='bars')", etc. This allows me to have the parent/child hierarchy > that I want, and access the children in the appropriate groups, but it feels > rathr ugly, and I'd still like an aggregate 'children' set so that I don't > have > to use each set individually (and update every use if I ever add new > subclasses). > > Additionally, I don't know if I'll need this, but I'm interested in how I > might > get a link to 'children_of_same_type', so in Foo it would be an alias to > 'children', but in Bar it would be an alias to 'bars', etc. I can't just do > 'children_of_same_type = bars' because 'bars' is autogenerated so hasn't been > defined yet. > > I hope that makes sense, but if not I can come up with a few more examples to > try to clarify it. > > Does anybody have any suggestions as to how I should structure this? Would I > be > best to leave the parent links as they are and define custom Managers for > 'children' and 'children_of_same_type'? If so, pointers on how to go about > this > would be appreciated. > > Thanks, > Nye Why don't you instead of subclass Foo just create a foreignkey to Foo or a OneToOne with foo. 'foo_object.children.all()' I don't think that this is possible because it contains different models in the query. The other option that you could try is a generic relation something like the way django-tagging works. I hope this is a 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 -~--~~~~--~~--~--~---
How to Model Formset
The only way to describe what I am trying to accomplish is through an example. Here are my models class B(models.Model): credits = models.FloatField(,null=True) class A(models.Model): b = models.OneToOneField(B) description = models.TextField() I want to get a formset of A forms for each item in B.objects.all(). One requirement is that I only want it to save if they fill in a description. The other requirement is that in the form I don't want the user to be able to change the value of b. This is the reverse of an inline formset. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
custom form validation in newforms-admin
I am using newforms admin and need to be able to have a validation check against multiple fields on the form. I was reading that all you need to do is to go form_change = MyCustomForm() from within your subclass of admin.ModelAdmin however it seems like this has changed since the post that I read. Does anyone know how to accomplish this with the most recent svn copy of newforms-admin? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: custom model field validation
On Feb 7, 2:53 am, Pigletto <[EMAIL PROTECTED]> wrote: > On 7 Lut, 09:58, Mackenzie Kearl <[EMAIL PROTECTED]> > wrote:> I am having trouble finding documentation on how to add custom > > validation to a custom model field. > > > example: > > > class PostalField(models.CharField): > > def __init__(self,*args,**kwargs): > > kwargs['max_length']= 6 > > super(PostalField, self).__init__(*args, **kwargs) > > > def get_internal_type(self): > > return "CharField" > > Seems that you're mixing two types of fields here: fields from > django.db.models and fields from django.newforms.fields. > For this kind of validation (with postal code) you should create > custom newforms field or write custom validator for a form. > This is described at newforms documentation. > > HTH > > -- > Maciej Wisniowski So If I create a newforms field then how do I tell the admin to use that when building the form in the admin? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
custom model field validation
I am having trouble finding documentation on how to add custom validation to a custom model field. example: class PostalField(models.CharField): def __init__(self,*args,**kwargs): kwargs['max_length']= 6 super(PostalField, self).__init__(*args, **kwargs) def get_internal_type(self): return "CharField" now when I save from the admin with this field it only validates like a CharField. How do I fix this to use some function like below. def validate(self): pattern = re.compile("([A-Z,a-z][0-9]){3}") if not pattern.match(value): raise forms.ValidationError('Not A valid Postal Code') --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Sitemap Index problems
Hi I am trying to get a sitemap index generated however I only get "Exception Type:ValueError Exception Value:Empty module name" I am not sure what I am doing wrong. urls.py sitemaps = { 'blog':BlogSitemap, 'gallery':GallerySitemap, } urlpatterns = patterns('', (r'^sitemap.xml$', 'django.contrib.sitemaps.views.index', {'sitemaps': sitemaps}), (r'^sitemap-(?P.+).xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}), ) sitemap.py from django.contrib.sitemaps import Sitemap from paddlecrazy.blog.models import Post class BlogSitemap(Sitemap): def items(self): return Post.objects.all() def lastmod(self, obj): return obj.modified I can get the sitemap-.xml files just fine however the index does not work Thanks Mackenzie --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Count the times a user has logged into the system
you can just create a profile with a field number of times logged in. This could be updated in a custom login view that you write. check out http://www.djangobook.com/en/beta/chapter12/ def login(request): username = request.POST['username'] password = request.POST['password'] user = auth.authenticate(username=username, password=password) if user is not None and user.is_active: # Correct password, and the user is marked "active" auth.login(request, user) # Redirect to a success page. return HttpResponseRedirect("/account/loggedin/") else: # Show an error page return HttpResponseRedirect("/account/invalid/") --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: 404 for date-based generic views--Help!
You should put some template code up as well i know that I recently could not see posts that existed because allow_future: defaults to False http://www.djangoproject.com/documentation/generic_views/#django-views-generic-date-based-archive-day --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---