Prevent Url Form from clearing out - django

I am currently working on a Django project and wanted to create a form that includes the invitation link as the initial URL and a field for the maximum usage of that link. However, when I decide that I want to publish this link, the form is cleared, so the user is not able to publish the link afterwards. Any ideas on how to prevent this or is there another way to solve this problem.
form in forms.py
view in views.py
functions in functions.py

Related

How can I change the view site link in Django admin, depending on which app is used?

I am making a project where each client have their own app. This is because they have similar pages but not exactly the same so I think it's a good approach(I may be wrong) to just copy one app for each new client. I have not tried it yet, I am still planning for it. I see one problem with the view site link in the admin. I will let the clients use the admin. How can I set the view site link to the main page for the client? One way to solve it would be to leave it as is and have a function checking their user name and redirecting to the right app. But is there any other way to solve this problem?
I don't think it will be a good idea to have applications generated for users as that's too much once you reached a specific amount of users.
they have similar pages but not exactly the same
Then what you should do is to, after getting the user in your view, pass in a different context to your template. Something like:
def my_view(request):
# First assign different context to different users
context = {'data': 'whatever each user gets', 'other': 'put in more than 1 data',}
return render(request, 'myapp/index.html', context)
I will let the clients use the admin
That's not a good idea as the clients MUST be a superuser to view the admin site. Otherwise, you need to change the permissions of a superuser, make a separate superuser if you are the maintainer of the site, and all sorts of trouble. Just take some time and make your own templates.

How to Fill Form with Data in DJango without Update

New to Django here. I have a link to a form in DJango. I use the CreateView to have the user enter the initial information. It all works great and the data is accurately saved to the database. My issue is this: I would like that same link to open the form (it's a one-to-one relationship) with the filled data so the user can see what they have previously entered and correct, edit or update as needed. The form currfently opens as a blank form so if the user has entered that information previously they are unable to see it. I cave researched get_or_create and update_or_create as well as a number of other topics, but can't seem to figure this out. This needs to be a user-friendly experience so multiple entires or clicking multiple buttons to access the data is not an option. How best can I implement this?
#Don you can checkout django formsets, I think this will help in this situation. And you can use a single FormView for all your needs by overriding its methods.
Have you looked at Django Sessions. It’s a simple way of saving session data and passing the data to future requests. https://docs.djangoproject.com/en/3.0/topics/http/sessions/. I. In your form view you cloud save the session data you want to pass to your next form. In your next form, you could use the session data as default values. I’ve done something similar in the past.

Form in Footer and multi form in Django

Hello Is there any way to accept a input from footer? I have a footer which is for Newsletter signup. Users insert their mail there. How could I accept that data? Do I need to send form via views every time. or there is a way to accept form from that included template code?
Well I also have a feedback form in the footer which in included in all the pages I want the feedback to be stored in my DB. I cannot figure out how I can accept the form data from all pages. (Sending forms in all page through views is possible But I think there is A easy (good Looking) idea) and also There are more them one Post method. I really don't know how to Explain. But I expect you can understand me.
I breakdown the your multiform/newsletter signup in steps as below:
Define view the post view
Add route to the url.py
In your html template add action in form tag example for
Validate input in your defined view
Save it.
That's it.

Redirect a custom form to django admin form

I created a custom admin form for a particular model. All functionalities working. Now I want to call this form from the click of a button on another page that I have created. I was able to do that by creating an object of the form class, but it doesn't render the form as the admin site does (I had some fieldsets etc defined). Can I straight away redirect to the admin site's form? That would avoid duplicating the code for how I handle the form data. Any other leads would also be appreciated.
Now I want to call this form from the click of a button on another page that I have created.
Is this also within the admin interface? If so, don't use the admin view for all your users. As that will require nasty stuff with groups, permissions, etc.
I was able to do that by creating an object of the form class, but it doesn't render the form as the admin site does (I had some fieldsets etc defined).
Isn't this as expected, as the admin site comes with its own css and javascript? So you need to write it yourself
Can I straight away redirect to the admin site's form? That would avoid
duplicating the code for how I handle the form data. Any other leads
would also be appreciated.
True, but I believe the admin views have special authorisation checks on them. So you come back to the things with groups and permissions.
What I would do is move your form handling to an method in like utils.py and call this method from the normal and admin view.

Ajax - How to save automatically my Django form

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.