AttributeError: 'str' object has no attribute '_meta'
I'm trying to create my first Django app. When I attempt to validate, I receive the "str object has no attribute _meta" error. Can anyone provide any insight? I'm running from the dev branch, and have included the output of "./manage.py validate" Thanks! Traceback (most recent call last): File "./manage.py", line 11, in ? execute_manager(settings) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/management.py", line 1343, in execute_manager execute_from_command_line(action_mapping, argv) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/management.py", line 1260, in execute_from_command_line action_mapping[action]() File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/management.py", line 1013, in validate num_errors = get_validation_errors(outfile) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/management.py", line 885, in get_validation_errors for r in rel_opts.get_all_related_objects(): File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/db/models/options.py", line 124, in get_all_related_objects if f.rel and self == f.rel.to._meta: AttributeError: 'str' object has no attribute '_meta' --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: AttributeError: 'str' object has no attribute '_meta'
Hmm... Looks like I fixed this. I had: from app.user.models import UserProfile [...] owner = models.ForeignKey('UserProfile', related_name='foo') I changed it to: from app.user.models import UserProfile [...] owner = models.ForeignKey(UserProfile, related_name='foo') Is this a bug, or was my understanding of quoted ForeignKey values incorrect? 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: AttributeError: 'str' object has no attribute '_meta'
And this is one of the many reasons I love Django the community. Highly informative response, for which I 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: Django chokes on template blocks?
So... I'm relatively new to Django, but... You have "{% block content %}{% endblock %}" (note: this is from the image posted) My suggestion would be to try putting a space between the tags. I don't have Django in front of me, so I can't test this, but it looks like it's expecting content in the block tag and trying to perform an operation on it. Since there is no content, it might be getting confused. I may be very wrong, but that's my first though. Cheers! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Django chokes on template blocks?
Adrian Holovaty wrote: [...] > > This comment is inaccurate. {% block %} tags are not required to have > any space between them. "{% block content %}{% endblock %}" -- with no > space -- is perfectly valid. Sorry about that. Thought I understood what was going on, for a change. Good luck finding a resolution... I'll step back into the shadows on this one. Cheers! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Difficulty accessing via related_name
Hi folks, I'm trying to develop an application that 'extends' the User object. I'm using the 'related_name' argument for ForeignKey to access the related objects through request.user I have a class, similar to this == class Foo(models.Model): user = models.ForeignKey(User, edit_inline=models.TABULAR unique-True, related_name='foo') def __str__(self): return "Foo ID#%s" % self.id def some_function(self): return "Result" == If I try to display the relationship, I'd expect to get 'Foo ID#1', but I get this... == print "User's Foo: %s" % request.user.foo == When I try to traverse the reference, I can't access any of the functions or attributes == request.user.foo.some_function() AttributeError at /foos/1/ 'RelatedManager' object has no attribute 'some_function' == Am I doing something wrong? Making an incorrect assumption about the functionality of Django? Any insight would be appreciated! Thanks! --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Concurrency and data modification
I'm wondering if there's any way to handle concurrent modification of data in a django application. Say I have a class: == class ViewCount(models.Model): object = models.ForeignKey(Foo) count = models.IntegerField(default=0) == I'd like to be able to do something like: == def incrementCount(target_count): target_count.count = target_count.count + 1 target_count.save() == Conceptually, if multiple servers are running, and 2+ try to update the count at the same time, it's possible that the new total would be incorrect. (For completeness: A reads 0, A writes 1, B reads 1, C reads 1, C writes 2, B writes 2... count is 2 but should be 3) Does Django have an integrated solution to this sort of problem? If not, does the community have a 'best practice' for dealing with this? Thanks! --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Difficulty accessing via related_name
Ah ha! Thank you... I now see the error of my ways! Since I'm using unique=True, is there any way to avoid the [0] mumbo jumbo? (I don't see any but I figure it won't hurt to ask). Thanks, --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Concurrency and data modification
I don't think that transactions are enough to solve this problem, but I could be wrong. My understanding of a transaction is that it will prevent a write after a write, but not a read after a read... so if both read before either writes, the data will be incorrect. The data might also come from a cache, but the underlying issue is that the data is removed from the database before being returned. PLEASE CORRECT ME IF I'M WRONG. example A starts transaction, A reads 0, A writes 1, A ends transaction, B starts transaction, B reads 1, C starts transaction, C reads 1, C writes 2, C ends transaction, B writes 2, B ends transaction /example In tutorial 4's commentary, a similar problem was addressed, and Adrian's solution was to 'create a custom method on your model that does an "UPDATE polls_choices SET votes = votes + 1 WHERE id = %s".' I'm not quite sure how to make this happen... I didn't see any place to specify raw SQL to pass to the DB except for the SELECT statements that define a QuerySet (that doesn't mean they're not there). How does one specify raw SQL outside of a QuerySet? As an aside, this seems like a common design pattern... so maybe a .increment() method for 'IntegerField's would make sense. Thanks! --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Concurrency and data modification
How does the cache framework with respect to transactions? If I update a field at the database level, and it locks it... wouldn't it still be possible to grab a stale copy from the cache? Thanks, --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Concurrency and data modification
How does raw SQL interact with the 'save' function? Say I need to: increment 'count' set another variable on the same object Do I need to write custom SQL to update the second variable? Can I just use .save() and have it work as I want it to (or will count be changed to the old value)? How can I keep the database value and the django-viewed value the same... can I do the update SQL and then 'self.count = self.count + 1'... is there any way to 'freshen' the value after the update so that .save won't be impacted? Thanks, --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Concurrency and data modification
I think that this would be great (for my purposes)... It doesn't look like this exists in Django right now. Are there plans to implement this? Maybe a ticket that already exists? I'd still be concerned about the cache getting in the way, but as a first step the 'for_update' addition would be fantastic. Thanks, Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Forms with error reporting
The FormWrapper design pattern seems to be great, but I have a question. Is there any way that I can put errors in the response that aren't linked with form fields? For example, in an authentication page... if the authentication fails, I don't want to link an error to either the user or password field... it should be linked to the page. I guess what I'm looking for is something like 'form.generic.errors' Thanks in advance, --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Forms with error reporting
The example shows only field-specific errors... == {% if form.has_errors %} Please correct the following error{{ form.error_dict|pluralize }}: {% endif %} ... {% if form.name.errors %}*** {{ form.name.errors|join:", " }}{% endif %} == As I understand it, this block is only determining if there are errors on the page and if there are one or many. Then it progresses into per-field errors. I'm looking more for: == {% if form.has_errors %} Please correct the following error{{ form.error_dict|pluralize }}: {% if form.generic.errors %}*** {{ form.generic.errors|join:", " }}{% endif %} {% endif %} ... == I could do this by defining a 'generic' field and manually assigning errors to it, but that seems like a kludge. Thanks for your feedback so far, --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Request for 'transaction' disambiguation
Hi all, I'm poking-around with transactions... and I must admit I'm confused as to how to properly implement transactions in Django. I'm trying to make use of "Tying transactions to HTTP requests", but I'm not having much luck. I've placed TransactionMiddleware in the MIDDLEWARE_CLASSES. I tried: == ... foo.value = "foo" foo.save() # something that generates an error bar.value="bar" bar.save() ... == But "foo" was still being set while "bar" wasn't. My expected outcome was that neither would be set. Then I tried: == ... foo.value = "foo" # NO ERROR is generated bar.value="bar" ... == And now neither "foo" nor "bar" were being set. Can anyone help me figure out what I'm doing wrong? Thanks! --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Request for 'transaction' disambiguation
Nevermind... Looks like Django defaults to the default MySQL table type (MyISAM), which doesn't support transactions. My fault completely. --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Request for 'transaction' disambiguation
Yeah... I added a comment to the docs, but "default-storage-engine=innodb" is the way that I configured it, and it works. Thanks for the feedback though. --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Boolean logic in .filter on QuerySets
Is is possible to make use of boolean logic in QuerySet filters? Say I have two dates: my_model.foo_date my_model.bar_date I'd like to do my_model.objects.filter(foo_date__gt=somedate OR bar_date__gt=somedate) Obviously that syntax isn't valid, but does something exist to allow that sort of logic? Thanks, --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Model-level DB cache
I had the same reaction at first... "this has to be a transaction issue", but I decided to give it a try. I'm working from trunk, and here's what I did to recreate the problem: == {{ In manage.py shell }} >>> a = Foo.objects.all() >>> a [< Foo: Foo 5>, < Foo: Foo 6>, < Foo: Foo 7>, < Foo: Foo 8>] {{ In MySQL shell }} delete from foo_foo where id=8; commit; exit; {{ In same manage.py shell }} >>> a [< Foo: Foo 5>, < Foo: Foo 6>, < Foo: Foo 7>, < Foo: Foo 8>] >>> b = Foo.objects.all() >>> b [< Foo: Foo 5>, < Foo: Foo 6>, < Foo: Foo 7>, < Foo: Foo 8>] >>> transaction.rollback() Traceback (most recent call last): File "", line 1, in ? File "[...]/django/db/transaction.py", line 161, in rollback set_clean() File "[...]/django/db/transaction.py", line 102, in set_clean raise TransactionManagementError("This code isn't under transaction management") TransactionManagementError: This code isn't under transaction management >>> b[3] < Foo: Foo 8> == Maybe we're making the same mistake, but this behavior seems strange to me as well. --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Django and Media Temple Grid Server
> I do not understnd why some people build a > new sytem using 2 years old software (2.3.5 > released in Feb 2005). So far as I understand, MediaTample's servers are all based on RedHat's ES/AS offerings. I tried to get Django running on a dedicated server with MT before, but gave up (on MT, not Django) because it would have meant leaving RedHat's support for Apache, Python, and mod_python. I really hope that they offer their grid setup for Django -- I think it would be a huge benefit for the community to have a provider the size of MediaTemple encouraging use of Django. --Ben --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: web sites using clusters
Django works very well in a multi-server two-tiered environment. (Web + DB) I'm pretty sure that this was one of the goals of Adrian, et al. as they developed Django. As long as your database cluster can handle the traffic, you can keep adding Django webservers with an outward-facing load-balancing scheme. The web servers don't need to talk to each other, but make sure your database is using transactions and the proper isolation level for your needs. I don't know of any tutorial for setting up a Django cluster, but it's really just "add more servers" and "synchronize the applications they're running". There are likely tutorials for setting up generic web server clusters, and Django shouldn't be much different. I use subversion to keep all of my servers running the same code, but other options are certainly possible. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: web sites using clusters
It should be noted that they don't offer shell access; so, while it is theoretically possible to get Django to run on the Mosso service, you wouldn't have access to manage.py. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---