This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'm writing some models. Specifically, a UserProfile model which is created by a post save hook on User.
Some strange things are happening here. The test suite passes on one computer, and fails on another. The error message is : profile_userprofile.organization_id may not be NULL, and yet here is my model:
class UserProfile(models.Model):
'Profile object for a user'
user = models.ForeignKey(User, unique=True)
organization = models.ForeignKey(
'organization.Organization',
related_name='volunteers',
null=True,
)
obviously, organization should allow null values, but it doesn't. Any ideas as to what's going wrong here? The same thing happens when calling User.objects.create() from the shell.
(oh, here's the hook)
#receiver(models.signals.post_save, sender=User)
def user_post_save(sender, instance, **kwargs):
'create a userprofile object for a user if one does not exist'
UserProfile.objects.get_or_create(user=instance)
Sounds like the database is not on sync in the second machine. Drop it and re-run syncdb.
Perhaps what you are looking for is blank=True.
I was missing a migration! Whoops!
Related
this is my first question here, nevertheless S.O. is my main point of reference and support while developing my coding skills with Django.
Thanks on advance to all people who is part of SO!
My main question is: Under your experience, in which situations you needed to extend User Model? is it a common thing to do? ... all tutorials and blogs I have read says ... "for example, if you want to use an email insted a username". But this doesn't sound like a real reason to me, I haven't found other reasons than this.
If I want to use email as username I can create a user-creation form with a field to get username and allowing only emails. This will perfecly solve the problem right?
In my case I followed Django official recommendation:
it’s highly recommended to set up a custom user model, even if the
default User model is sufficient for you. This model behaves
identically to the default user model, but you’ll be able to customize
it in the future if the need arises.
So I did this:
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
I'm ready, but ready for what? Please enlight me.
The second part of my question is: Let's imagine in the future I want to register more information about the users of my blog (country, gender, etc.) ... is it possible to create a profile table and point it with 1-to-1 relationship to my extended User model (which does nothing but is ready for the future)? Should I do it now that I have already dropped and created the database again?
Thanks a lot and sorry if I wrote too much.
Best regards,
goka.
If your website need to collect more user information, like, company, telephone, zip code. Also, maybe you need to classify user, like, level_1, level_2, something haven't be define in User model. Then, it's better to create a profile model.
If you already have some user registered, then you add new profile model, it may cause your future coding very messy, like, one year later, you or other software engineer may assume all User have 'profile', and directly use user.profile.something without checking whether profile exists or not or a user, that will throw exception.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a competition management application that I will be hosting with heroku. Every user of the application would need certain things like an integrated registration store which also plug in the entries so that the registrants can be judged and access to all of their information after the competition to provide results. I dont know how to build this around a profile system that lets you manage your competitions so I was thinking just duplicate the app upon request with a subdomain name for each new event that wants to use it. Is this a bad idea? Should I bite the bullet and figure out how to do the whole profile thing so its one app? - if so please point me in the right direction of how. I am using django
There's no need for multiple app per User, Just one app is enough and define your model something like ...!
class Competition(models.Model):
event_name = models.CharField(max_length=200)
result = models.IntegerField()
class Registration(models.Model):
user = models.ForeignKey(User)
competition = models.ForeignKey(Completition)
Just do event Registration in localhost.com:8000/competition/event_name or Do with your own logic here.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I have a model which allows users to upload an .ics file to a calender field via the FileField.
However this is not required so some objects will have associated files, other will not. In my template I want to output different things depending on this. I thought this would work...
My view passes a all the model objects in a seminarData variable..
{% for seminars in seminarData %}
{% if seminars.calender %}
{{seminars.title}}
{{seminars.message}}
Download .ICS File
{% else %}
{{seminars.title}}
{{seminars.message}}
{% endif %}
{% endfor %}
But this doesn't seem to work... Everything just goes straight to the else section even those objects with associated files in the calender field.
Could it becasue in my model I have
calendar = models.FileField(upload_to="/uploadedCal/", blank=True)
And I need to have null=True or something?
I played around inequality operators aswell with no luck... Thanks
Edit: I think the solution would be pretty straightforward I just can't see it annoyingly!
Calendar is spelt incorrectly in your if statement ;-)
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
i am trying to obtain how much likes one of my pages has, and only this one page isn't showing the likes field, even having about 1 thousand likes, check it out:
https://graph.facebook.com/233572770052788?fields=likes
{
"id": "233572770052788",
"type": "page"
}
This one, responds just fine:
https://graph.facebook.com/173268742773034?fields=likes
{
"likes": 348,
"id": "173268742773034",
"type": "page"
}
If you are using Like button for your non-facebook page.
Then you may retrieve number of likes as follows:
https://api.facebook.com/method/fql.query?query=select total_count from link_stat where url='http://tvg.globo.com/bbb/bbb12/videos/t/agora-na-casa/v/monique-tira-a-roupa-e-faz-a-alegria-da-casa/1762991/'
Try here
It uses following FQL Query: select total_count from link_stat where url='yourUrl'
Try opening a bug at facebook: https://developers.facebook.com/bugs
Facebook is full of bugs: http://www.quora.com/Is-it-true-that-Facebook-has-no-testers
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I have two django-apps.
news and comments
in news/models.py I import my comments with "from my_proj.comments.models import Comment"
and in my comments/models.py I import my news class with "from my_proj.news.models import News"
Then in my third app (named frontpage) I import News in the view.py.
But I get the error:
Could not import hb_frontpage.views. Error was: cannot import name News
If I delete the import in the comments/models.py file (and the functions that uses News) it works.
Anyone know how to solve this?
You don't actually need the News import at all. Looking at your code (which by the way should have been posted as an update to your question, not as an answer) the only reference to News is to look up the objects that are related to this particular comment. But Django has a built-in way of doing that from the comment itself:
news = self.news_set.all()
Using this, there's no need to get the News object and filter from there.
You can't do circular imports.
News needs comments to load, but to load comments you need to load news, but to load news you need to load comments but to load comments...
You should really only need to do one import. If you write what you are trying to do, I can give further advice.