The BlogPost model is SiteRelated so it does have a site_id attribute
(BlogPost -> Displayable -> Slugged -> SiteRelated). Take a look at the
current_site_id function in mezzanine.utils.sites to see how it determines
which site is active. When BlogPost is saved, the site_id is set by that
function.
K
On Sunday, January 31, 2016 at 7:59:53 AM UTC-8, wh4n wrote:
>
> With Site.objects.get_current() I can get (obviously) the current site
> object. But how do I get the site_id of a specific user so that I can save
> the post *only* to that site that the user is managing?
>
>
> For example I have two users that have different values in the database:
>
>
> username user_id site_id
> peter 1 1
> john 2 2
>
>
> How do I save with a Django ModelForm in a view like this so that I only
> post to the users site_id:
>
>
> def create_post(request):
> current_user_id = request.user.pk
> if request.method == "POST":
> form = BlogPostForm(request.POST)
> if form.is_valid():
> post = form.save(commit=False)
> post.author = request.user
> post.user = User.objects.get(id=current_user_id)
> post.published_date = timezone.now()
> post.save()
> return redirect('post_list')
>
>
> I haven't found a solution for this and any help is very great! At the
> moment it only saves to site_id = 1 which I suppose is because I have set
> SITE_ID = 1 in settings.py.
>
>
> Any help is very great!
>
>
> Thanks guys!
>
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.