I'm having trouble installing django-admin_action_mail from git.
I tried to install it via:
pip install
git+https://github.com/mjbrownie/django-admin_action_mail.git
But Django did not pick it up when I added it to settings.INSTALLED_APPS.
Did I miss something?
The admin code for that app is commented out (see here: https://github.com/mjbrownie/django-admin_action_mail/blob/master/admin_action_mail/admin.py ) so nothing is going to show up on the admin page - even if it's working and enabled.
It looks as though you need to create your own models to handle the mailing functions. Take a look at the README where it tells you to add something like the following in your app's admin.py:
from admin_action_mail.actions import mail_action
class MyModelAdmin(admin.ModelAdmin):
#Note all args are optional
actions = [
mail_action(
'description' : "Send Email to Related Users",
'email_dot_path' : 'email', # dot path string to email field (eg 'user.email')
'email_template_html' : 'admin_action_email/email.html'
'reply_to' : 'noreply#example.com' # defaults to request.user.email
)
]
admin.site.register(MyModel, MyModelAdmin)
Have you added a model like that to your own app's admin.py?
EDIT: As the problem appears to be with installation, the following should help:
You can add arbitrary paths to your wsgi path spec, that means it will pick up Python app modules in other locations. Assuming your app is installed in /home/user2161049/myapp you can put your external modules under /home/user2161049/myapp/external. In this case copy the contents of that app into /home/user2161049/myapp/external/admin_action_mail/.
To add this to your settings.py:
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(SITE_ROOT, 'external'))
The first line defines SITE_ROOT based on the current running script (setup.py) at startup. The second adds the external folder into the search path. You can put anything you want in there, and even define a specific folder somewhere else if you want to keep your externals out of your app folder. Restart the server and it should find the app just fine.
Related
I code app with Django == 2.2.3
By now i want to get all urls_patterns of all my project and associated view name.
How can i get something like this:
urls_patterns_view_names_list = [
("view_name", "view_name: url_pattern"),
...,
...,
...,
]
I have seen several topics to the question of url patterns but none correspond and do what I want. For the most part the answers are very old and obsessive for my case. That's why I reformulate my question: I want to have the urls patterns and for each url associated the name of his view: How can I do that with Django 2.2.3 on python 3.7?
You can achieve this with django-extensions:
pip install django-extensions
Then in settings.py:
INSTALLED_APPS = [
...
'django_extensions',
...
]
And finally in your command line:
./manage.py show_urls
This will result in exactly what you want. From the package docs:
show_urls: Produce a tab-separated list of (url_pattern, view_function, name) tuples for a project.
It's not directly trivial, but I've written a module, https://github.com/valohai/django-urr, that has utilities for working and traversing Django URL resolvers.
If you end up using it, you can just use
for entry in django_urr.extract_urls():
print(vars(entry))
– see here for all of the contents of entrys.
I'm trying to setup the admin to show settings meant to be stored in database backend (Postgres 9.5.0). I manually created values in shell_plus as follows:
In [1]: from constance.backends.database.models import Constance
In [2]: first_record = Constance.objects.get(id=1)
In [3]: first_record
Out[3]:
pg-admin properly shows the entry although django admin doesn't show it at all. I ran migrate command for both databases (I have default and product databases) but the record still is not showing up. Certainly I can make it work with forcing to register with admin as follows:
admin.site.register(Constance)
but my question is if it's necessary?
Yes, they do.
You need to manage dependencies, but you can just use next command to install:
pip install "django-constance[database]"
Also you need to add some additionl settings to your settings.py :
CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
INSTALLED_APPS = (
# other apps
'constance.backends.database',
)
#optional - in case you want specify table prefix
CONSTANCE_DATABASE_PREFIX = 'constance:myproject:'
Then you need to apply migrations by running command python manage.py migrate database
For displaying settings inputs in admin you should specify them in your settings.py. There are various types of fields and you even can add your own types of fields using CONSTANCE_ADDITIONAL_FIELDS parameter.
CONSTANCE_CONFIG = {
'THE_ANSWER': (42, 'Answer to the Ultimate Question of Life, '
'The Universe, and Everything'),
}
You can read more at documentation page.
I an trying to get django-facebook to work as per instructions given in the readme on
https://github.com/tschellenbach/Django-facebook. I am new to django.
It looks simple but I am facing the following problems. I am not able to get it to work.
In the readme it says AUTH_USER_MODEL = 'member.FacebookUser'. I am guessing the right option is
AUTH_USER_MODEL = 'django_facebook.FacebookUser'
after importing the models - this took me some t even after making that change, syncdb throws an error stating that:
FacebookUser does not have a USERNAME_FIELD.
Not able to solve that I decided to use the default user model - auth.user. That works and I was able to load facebook/example. However after authentication from facebook, I get an error
You need to set AUTH_PROFILE_MODULE in your project settings
So I added AUTH_PROFILE_MODULE = 'django_facebook.FacebookProfile'
Now it returns a new error -
FacebookProfile matching query does not exist. Lookup parameters were {'user_id_exact': 2L}
What should I do now?
Do python manage.py syncdb or whatever it needs to be done to update your database schema with the new table (facebook_profile).
Also, you don't mention it but I have and app that uses django_facebook and I have my settings.py file like this:
TEMPLATE_CONTEXT_PROCESSORS = (
...
'django_facebook.context_processors.facebook',
...
)
AUTHENTICATION_BACKENDS = (
...
'django_facebook.auth_backends.FacebookBackend',
)
I hope it helps
I'm trying to use django-tinymce to edit fields in django admin.
I've the app installed in my virtualenv (django-tinymce==1.5.1b4). It's listed in my installed apps -
INSTALLED_APPS = (
#...
'tinymce',
#...
)
My settings includes the following
TINYMCE_DEFAULT_CONFIG = {
'theme': "advanced",
'theme_advanced_toolbar_location': "top",
'theme_advanced_buttons1': "bold,italic,underline,separator,"
"bullist,separator,outdent,indent,separator,undo,redo",
'theme_advanced_buttons2': "",
'theme_advanced_buttons3': "",
}
TINYMCE_SPELLCHECKER = True
TINYMCE_COMPRESSOR = True
And I've got the files available at /MEDIA_ROOT/js/tiny_mce (the default).
My models look like -
from tinymce import models as tinymce_models
class MyModel(models.Model)
post = tinymce_models.HTMLField()
When I go to the model admin page, the field appears as a normal text field and my browser tells me there's an error on the inline js script for the field. It says it doesn't recognise the variable tinyMCE. It doesn't look like the page is even trying to load the js file (I'm getting no 404's - I can't see any sign of anything being loaded).
I'm not sure what I'm missing..
Have You, Sir, done python manage.py collectstatic ?
What value variable in settings.py is in TINYMCE_JS_ROOT and TINYMCE_JS_URL
If variable TINYMCE_JS_URL is not set check if You, Sir, have file at /MEDIA_ROOT/js/tiny_mce/tiny_mce.js. If not, try to copy manually from django-tinymce's egg.
OK, looks like it might have been a bug in the django_tinymce code. I've reverted to 1.5.1b2 and everything works as expected. Guess I should look into filing a bug report.
I am trying to de-couple two apps:
Locations - app containing details about some location (town, country, place etc)
Directory - app containing details of places of interest (shop, railway station, pub, etc) - all categorised.
Both locations.Location and directory.Item contain lat/lng coords and I can find items within a certain distance of a specific lat/lng coord.
I'd like to use the following URL structure:
/locations/<location_slug>/directory/<category_slug>/
But I don't want to make my directory app reliant on my location app.
How can I translate this url to use a view like this in my directory app?
items_near(lat, lng, distance, category):
A work around would be to create a new view somewhere that translates this - but where should I put that? if it goes in the Directory app, then I've coupled that with my Location app, and vice versa.
Would a good idea be to place this workaround code inside my project URLs file? Thus keeping clear of both apps? Any issues with doing it like this?
For your urlpattern to work, the view function invoked has to be aware of both Locations and Directories. The short answer is you can put this view function anywhere you want - it's just a python function. But there might be a few logical places for it, outside of your Directory or Location app, that make sense.
First off, I would not put that view code in in your top-level urls.py, as that file is intended for URLconf related code.
A few options of where to put your view:
Create a new view function in a file that lives outside of any particular app. <project_root>/views.py is one possibility. There is nothing wrong with this view calling the item_near(..) view from the Directory app.
# in myproject/urls.py
urlpatterns = (
...
(r'/locations/(?P<location_slug>[\w\-]+)/directory/(?P<category_slug>[\w\-]+)/',
'myproject.views.items_near_from_slug')
)
# in myproject/views.py
from directory.views import items_near
def items_near_from_slug(request, location_slug, category_slug):
location = get_object_or_404(Location, slug=location_slug)
distance = 2 # not sure where this comes from
# And then just invoke the view from your Directory app
return items_near(request, location.lat, location.lng, distance, category_slug)
Create a new app and put the code there, in <my_new_app>/views.py. There is no requirement that a Django app need to have a models.py, urls.py, etc. Just make sure to include the __init__.py if you want Django to load the app properly (if, for instance, you want Django to automatically find templatetags or app specific templates).
Personally, I would go with option 1 only if the project is relatively simple, and <project_root>/views.py is not in danger of becoming cluttered with views for everything. I would go with option 2 otherwise, especially if you anticipate having other code that needs to be aware of both Locations and Directories. With option 2, you can collect the relevant urlpatterns in their own app-specific urls.py as well.
From the django docs here if you're using django >=1.1 then you can pass any captured info into the included application. So splitting across a few files:
# in locations.urls.py
urlpatterns = ('',
(r'location/(?P<location_slug>.*?)/', include('directory.urls')),
#other stuff
)
# in directory.urls.py
urlpatterns = ('',
(r'directory/(?P<directory_slug>.*?)/', 'directory.views.someview'),
#other stuff
)
# in directory.views.py
def someview(request, location_slug = None, directory_slug = None):
#do stuff
Hope that helps. If you're in django < 1.1 I have no idea.
Irrespective of how much ever "re-usable" you make your app, inevitably there is a need for site-specific code.
I think it is logical to create a "site-specific" application that uses the views of the reusable and decoupled apps.