I am new to Django and trying to create a registration form for users. I want users to upload there image during signup. After some research I got django-avatar and easy thumbnail as way to go, am I correct? So I went ahead with django-avatar but I am confused how to add a form field to userprofile that talks to django avatar. Am I in correct path or should I use some other plugin for uplaoding an user image. If Django-avatar is the way to go how should I create a form field for image and how my view look like?
Try using Formsets with the form set to avatar.forms.UploadAvatarForm
Related
I am quite new to django, I know little terms... so it will be appreciated if you would answer more specifically how to implement. <3
I am working on a web development assignment about an image sharing platform. functionality involves users upload, download, delete and search images, etc.
recently I have implemented 'allauth' plugin to my site so that users can login in to the site, also I created an app called 'AllImages' with a model - 'Image'.
MY QUESTION IS:
How can I link the users to 'AllImages' and 'Image', so that the system knows who uploaded a particular image.
because I want to only let the uploader himself being able to delete his image
I really know nothing about the plugin, its just done by someone haha....
this is the allauth plugin
In your Images model add a foreign key field to user.
from django.contrib.auth.models import User
Further you can query something like..
Images.objects.filter(user=logged_user) to get all images of this particular user.
Django auth User
I am trying to let my users upload multiple pictures to their blog posts. I have created a model for the blog post and a separate model for the images and used a foreign key to relate them. I was planning on using dropzone.js so that the user can drag and drop the pictures. I have looked into using formsets but can't get my head around them. Can anyone explain to a django beginner how to go about doing this? Or better yet give an example? Thanks!
I have done something similar using jquery-fileupload. Never used dropzone.js so maybe the explanation is not directly equivalent, but this is roughly what you do.
If you don't want to use formsets, upload the images via AJAX and add hidden fields to the form with the primary keys of the uploaded images, so you can attach them when saving the blogpost in Django. You will have to deal with orphaned images (those that were uploaded but the blogpost was never saved.)
If you want to use formsets, Django expects a format in the posted form data, you just need to make sure you create in your html (with dropzone js templating) the apropriate format Django is expecting, and also incrementing/decrementing the counter of the formset's management form.
Neither way is trivial, you need to pick a path and bang your head a few times before having it working.
i have an add_form under my django app. i want to add a feature this form which is saving form automatically after user starts to type.
like in gmail , or blogger.
what are the steps i should follow? which way or plugin? and how to use them?
any knowlenge can help me.thank you.
There's two useful jquery plugins to get you started
https://github.com/BenGriffiths/jquery-save-as-you-type which saves what you type locally to a cookie client-side. Using this plugin is simpler and you will only need to actually save into your django backend when the user hits your form's "save" button.
and
https://github.com/nervetattoo/jquery-autosave which requires that you set up an intermediary model (perhaps a Draft model) in django to keep track of updates along the way. And when the user finally hits save, a final copy of the data is then saved into the actual model.
I'm creating a new app in django environment. I want to upload image of user when he/she sign-up's in my app and i want to use the same image when he/she posts any comment in my app. So how to integrate image-uploading code into my app code?
You should be using UserProfile as has been answered here Django user profile and have the ImageField in there.
Then create a ModelForm for the UserProfile and render it wherever you want the user to setup their profile and add a user image. The Model form will render the ImageField as a file upload field and have default handles for it. Make sure you have MEDIA_URL configured in your settings.py. You would also need PIL installed in your path for the image upload to work.
You can access the UserProfile instance for your user doing user.get_profile in your templates and as a callable elsewhere.
I'm in my first week of Django development and am working on an admin page that will let me write some quick html using TinyMCE and then save it to the database. I don't need to display this web page on the site or add it to urls.py, etc. The html snippet will be loaded from the database and used in a view function.
I've read in "Practical Django Projects" how to integrate TinyMCE, so my question is more concerned with the best approach for the form itself. Specifically:
1. Is there a built-in form like flatpage that works well for this? I only need one field in the form for the html.
2. How do I save the form's text after it's entered?
I created a model with a JSONField to save the html in, but I'm not clear on what to do next. Thanks.
here is the documentation for Django Flatpages App, maybe you serve.
I ended up using the ModelAdmin class to get what I wanted. I created a new model in models.py and then used ModelAdmin to enable an admin-editable form for the model's data.
Hope this helps someone.