diff --git a/docs/plugins/development.md b/docs/plugins/development.md index 232cd18da..7fd8badf3 100644 --- a/docs/plugins/development.md +++ b/docs/plugins/development.md @@ -53,10 +53,9 @@ from setuptools import find_packages, setup setup( name='netbox-animal-sounds', version='0.1', - description='Show animals and the sounds they make', - url='https://github.com/example-org/animal-sounds', - author='Author Name', - author_email='author@example.com', + description='An example NetBox plugin', + url='https://github.com/netbox-community/netbox-animal-sounds', + author='Jeremy Stretch', license='Apache 2.0', install_requires=[], packages=find_packages(), @@ -75,10 +74,11 @@ from extras.plugins import PluginConfig class AnimalSoundsConfig(PluginConfig): name = 'netbox_animal_sounds' - verbose_name = 'Animal Sounds Plugin' + verbose_name = 'Animal Sounds' + description = 'An example plugin for development purposes' version = '0.1' - author = 'Author Name' - description = 'Show animals and the sounds they make' + author = 'Jeremy Stretch' + author_email = 'author@example.com' base_url = 'animal-sounds' required_settings = [] default_settings = { @@ -161,14 +161,13 @@ For more background on schema migrations, see the [Django documentation](https:/ ### Using the Django Admin Interface -Plugins can optionally expose their models via Django's built-in [administrative interface](https://docs.djangoproject.com/en/stable/ref/contrib/admin/). This can greatly improve troubleshooting ability, particularly during development. To expose a model, simply register it with Netbox's `admin_site` object. An example `admin.py` file for the above model is shown below: +Plugins can optionally expose their models via Django's built-in [administrative interface](https://docs.djangoproject.com/en/stable/ref/contrib/admin/). This can greatly improve troubleshooting ability, particularly during development. To expose a model, simply register it using Django's `admin.register()` function. An example `admin.py` file for the above model is shown below: ```python from django.contrib import admin -from netbox.admin import admin_site from .models import Animal -@admin.register(Animal, site=admin_site) +@admin.register(Animal) class AnimalAdmin(admin.ModelAdmin): list_display = ('name', 'sound') ``` @@ -186,29 +185,39 @@ from django.shortcuts import render from django.views.generic import View from .models import Animal -class RandomAnimalSoundView(View): - +class RandomAnimalView(View): + """ + Display a randomly-selected animal. + """ def get(self, request): - # Retrieve a random animal animal = Animal.objects.order_by('?').first() - - return render(request, 'netbox_animal_sounds/animal_sound.html', { + return render(request, 'netbox_animal_sounds/animal.html', { 'animal': animal, }) ``` -This view retrieves a random animal from the database and and passes it as a context variable when rendering a template named `animal_sound.html`, which doesn't exist yet. To create this template, first create a directory named `templates/netbox_animal_sounds/` within the plugin source directory. (We use the plugin's name as a subdirectory to guard against naming collisions with other plugins.) Then, create `animal_sound.html`: +This view retrieves a random animal from the database and and passes it as a context variable when rendering a template named `animal.html`, which doesn't exist yet. To create this template, first create a directory named `templates/netbox_animal_sounds/` within the plugin source directory. (We use the plugin's name as a subdirectory to guard against naming collisions with other plugins.) Then, create `animal.html`: ```jinja2 -{% extends '_base.html' %} +{% extends 'base.html' %} {% block content %} -{% if animal %} - The {{ animal.name }} says {{ animal.sound }} -{% else %} - No animals have been created yet! -{% endif %} +{% with config=settings.PLUGINS_CONFIG.netbox_animal_sounds %} +