I am working on a website where the user can upload a post relating to a location and then they can add two or three photos to go along with it. I understand how to do a basic upload with either the Datastore or the Blobstore but I want to link these photos to the post and to the user and then be able to display them in all pages connected to the post and the user.
That is the general idea but to be more specific I am trying to figure out if it would be easier to just to give the post entities 3 db.blob attributes and take a little hit on higher data costs or if it is doable to link the Blobstore entities with my Datastore entities.
That's what BlobReferenceProprty is for. You can add a reference to a blob into model which seems to be what you want.
Here is a full example of uploading photo and associating it to user.
To associate users and photos it uses creates class UserPhoto that links user ID and photo blob keys.
Related
I am currently creating my first project and I am using an HTML template that I found online. It is a social media application where you should be able to upload a photo, like the photo, leave a comment, etc.
The issue is that I implemented all those functions, but liking, commenting, copying the URL (share buttong) refreshes the whole page and you end up at the very beginning of the page, because I am not sure how to refer the user to the post they liked/commented.
I am using
return redirect(f'{request.META["HTTP_REFERER"]}#{photo_id}')
, but since my posts don't have an unique identifier, it does nothing.
Any tips would be greatly appreciated. Thanks in advance!
It's so bad that the post doesn't have a unique identifier but you can use other fields to do it without an id field.
you can use some fields like DateTime and title and author name for making a hash and use it instead of an id field.
I'm currently working with some people to develop an application that will display a "sound library" when the user selects an option on their voip phone. The idea is that the phone system will pass a url with a device id in it, and that will open the django app to the users' library. I was told to remove login/user authentication in order to make the process easier for the user. My question is, is there a way to create a user field and save the model for future retrieval via the url request alone? Do I need to pass the device id to some hidden form first and redirect to the main page, and query the users' objects via the device id? I know there are security concerns but was wondering if it's even possible, any help is appreciated!
You should try using Djago REST Framework, it will make it easy to retrieve data with urls using unique identifier.
On my iOS app, when a user logs in I start a series of firebase listeners for my users data... Profile, Accounts, Campaigns, etc..
How and where would I do something like this is django/python? I have a firebase db. I configure it in the top of my views.py, I log the user in on my login view. At this point in the iOS app, I add it to an AppState File and can call it from any view. In django, I ended up calling the data and creating my "joins" in the actual view like so:
campaign_list = []
results = db.child('campaigns').get(refresh_token)
for campaign in results.each():
campaign = models.Campaign().db_snapshot(campaign)
result = db.child('accounts').child(campaign.userUUID).get(refresh_token)
campaign.account = models.Account().db_snapshot(result)
Now I have my campaign object and attached the account object. db is set from the config at the top of my views.py. I believe this the correct way? I know its weird to use firebase and django, and I'm slowly switching to postgresql, but in the mean time, I have to continue to use firebase.
So how do I create a so called snapshot of my user, then access the data when they visit specific views. Aka, create a list of accounts, then on the accounts view, show the list. Instead of creating the list when the user visits the view.
Is this caching? haha
I've read two tutorials on elastic search and that seems like one of the tools I will need. But I also create lists of the data. I.e. I add analytics to the account data. Like a join. Is this possible in elastic search?
The other talked about create_command core. This was interesting and potentially what I need, however, if I placed my listeners in there, it would start on the WebApp startup, but wouldn't know the logged-in users info, so I would have to create every list upfront...? The tutorials that I read on django didn't really go into this a whole lot. And I know Im supposed to keep sessions light.
Any help and links are appreciated!
Denis Angell
I am impressed with how wordpress handle the images (where user can upload and insert images into post). I want to make this feature to able applied in django. How do I achieve it?
Basically I have two models :
1.post - for writing the content
2.media - for uploading images/files
But in the post model I would like to able insert the images from the media model in the textField(). For the textField I am using django-tinymce for rich text context with filebrowser integration. So, better use the Image button to upload/insert image to/from media model.
Also the user only allow to browse the images that he/she uploaded in the filebrowser.
Lastly beside in the admin, this feature also need to work in frontend.
So is this possible?
I want to display a picture of the current_user in my template. How can I access the user's facebook id when I'm using django-allauth?
For each user that is signed up via a social account a SocialAccount instance is available. This model has a foreign key to User. Note that a user can connect multiple social networking accounts to his local account, so in practice there may be more than one SocialAccount instances available.
How you want to deal with this is project dependent. I can imagine one would want to copy the profile image locally, or perhaps you would want to give preference to the Google+ profile picture above the Facebook one, and so on.
The SocialAccount model has some helper methods that give you access to account basics such as the profile picture. All in all, this is a quick & dirty way to access first available profile picture:
{{user.socialaccount_set.all.0.get_avatar_url}}
The ID is also available:
{{user.socialaccount_set.all.0.uid}}
See also: https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/models.py#L72