Adding Maintenance Data pt 1

Join us as we continue building our product by starting to allow our users to add bike maintenance records to their bikes.

maintenance/models.py

from django.db import models

from django_extensions.db.models import TimeStampedModel

from core.models import DistanceModel


class Maintenance(DistanceModel, TimeStampedModel):
    activity = models.ForeignKey(
        'activities.Activity', on_delete=models.SET_NULL, null=True,
        blank=True)
    description = models.TextField(blank=True)
    place = models.CharField(max_length=255, blank=True)

    gear = models.ForeignKey(
        'gear.Gear', on_delete=models.SET_NULL, blank=True, null=True,
        related_name='maintenance')

    class Meta:
        get_latest_by = "created"
        ordering = ['-created']
        verbose_name = verbose_name_plural = 'maintenance'

    def __unicode__(self):
        return "{} {}".format(self.activity.user.username, self.created)

maintenance/views.py

from django.core.urlresolvers import reverse_lazy

from django.views.generic import CreateView

from .models import Maintenance
from .forms import MaintenanceForm


class MaintenanceCreateView(CreateView):
    model = Maintenance
    form_class = MaintenanceForm
    success_url = reverse_lazy('dashboard')

maintenance/urls.py

from django.conf.urls import patterns, url, include

from .views import MaintenanceCreateView

urlpatterns = patterns(
    '',
    url(r'^add/$', MaintenanceCreateView.as_view(), name='add'),
)

mento/urls.py

from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from django.contrib import admin

urlpatterns = patterns(
    '',
    url(r'^$', TemplateView.as_view(template_name='index.jinja'), name='home'),
    url(r'^accounts/', include('accounts.urls')),
    url(r'^maintenance/',
        include('maintenance.urls', namespace='maintenance')),
    url(r'^admin/', include(admin.site.urls)),
)
comments powered by Disqus