Comments (6)
Hi there @eduardo-matos, Currently you can manually create a UserPlan
by first creating a new User
in the admin and then edit his UserPlan
which is automatically created after user-creation. Is this what you were looking for?
As an aside: in order for this to work, you need at one plan marked as "default" plan. That way, all created users will immediately be assigned this plan after creation.
from django-plans.
I have some users that were created before including the django-plans app. The only way I can associate these users with an userplan is by editing via shell, which I was trying to avoid.
My idea was to create a new userplan manually (via admin page), choosing an existing user in the "create userplan" page. Since the "user" field is omitted, There is no way to do that.
from django-plans.
A quick fix is to override UserPlan inside your admin
from plans.models import UserPlan
from plans.admin import UserPlanAdmin
class UserPlanMyAdmin(UserPlanAdmin):
fields = ('user', 'plan', 'expire', 'active')
admin.site.unregister(UserPlan)
admin.site.register(UserPlan,UserPlanMyAdmin)
from django-plans.
Having user editable/writeable on the admin has one annoying con as well, which is when there are many users and simply loading them in a "select" html widget will cause load, especially when there are many users in the database.
If Django admin had a default feature to have a search-friendly select box for related field it would be much easier.
To learn more about this problem you may have a look at https://stackoverflow.com/questions/14912872/django-admin-dropdown-of-1000s-of-users.
To solve such issue there are:
- https://github.com/applegrew/django-select2
- https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields
My vote for the second option which is using raw_id_fields in admin panel.
Which gives something like:
The solution provided by @maxpaynestory is also an hack that can be done as well, but still will have the same problem that I described.
I am open for any suggestion here and would love to discuss it.
from django-plans.
For the problem with users created prior introducing django-plans
, I would recommend introducing adminaction to the sources. The code might be pretty simple:
for user in UserProfile.objects.filter(userplan=None):
UserPlan.objects.create(user=user, plan=Plan.objects.get(default=True))
Although there might be other cases, when the manual editation of UserPlans would be needed.
from django-plans.
An complete fix here is to use @maxpaynestory solution with Django 2+ autocomplete.
class UserPlanMyAdmin(UserPlanAdmin):
fields = ('user', 'plan', 'expire', 'active')
autocomplete_fields = ['user', 'plan']
from django-plans.
Related Issues (20)
- Use with django_rest_framework HOT 1
- Duplicated invoice numbers HOT 2
- Error expiring plans with Celery 5.0.0 HOT 4
- TAX is applied if the user fills in VAT ID without country code
- Add support for Django 3.2 HOT 1
- Migrating to Github Actions HOT 3
- Automatic publish to PyPI HOT 18
- Python 3.9, 3.10 support (install fails with `vatnumber`) HOT 3
- [bug] geolite2 missing from requirements
- Problem with Migrations
- Django plans cause error in sqlite3 backend HOT 2
- Demo project not work HOT 7
- Implement the multi user capability for one billing info HOT 1
- Implementing the price per unit
- Documentation incorrect and/or outdate
- Add support for trial plan
- Add ecomerce tracking to complete order HOT 2
- UNIQUE constraint failed: plans_plan.default HOT 2
- stripe and paypal HOT 3
- Quota.codename should be SlugField HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-plans.