-3

I am using angular js material for template and angular js for js. and since no timepicker in angular material js I am using a timepicker of moment.js I am using Django as a backend. I am puting data in the database through rest api the code of my angular template is here:

<md-input-container flex-gt-sm class="md-block">
        <label>Opening Time</label>
        <md-icon md-svg-src="/cityaplfreelisting/media/time.svg" class="mdicon"></md-icon>
        <input required  mdc-datetime-picker date="false" time="true" type="text" short-time="true"
               show-todays-date click-outside-to-close="true"
               auto-ok="true"
               min-date="minDate" minute-steps="1"
               format="hh:mm a"
               ng-change="vm.saveChange()"
               ng-model="data.openingTime ">
     </md-input-container> 

Actually my database is taking the value of openingTime in hh:mm:ss formar through rest api thats why I want to change the input format of time its showing in the format of 2018-01-23T12:38:07.439Z which is not acceptable for my django model

This is my django model

from django.db import models
from django.contrib.gis.db import models as gis_models
from django.contrib.postgres.fields import ArrayField
from django.conf import settings
from django.db.models.signals import pre_save
from django.utils.text import slugify
from multiselectfield import MultiSelectField


class Shop(models.Model):


    city = models.ForeignKey(City, on_delete=models.CASCADE)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)  # will change on_dlt method soon
    subCategory = models.ManyToManyField(SubCategory)
    filterTags = models.ManyToManyField(FilterTag, blank=True)
    owner = models.ForeignKey(settings.AUTH_USER_MODEL,default=1)

    slug = models.SlugField(unique=True, blank=True)
    shopName = models.CharField(max_length=250)
    tagline = models.CharField(blank=True, max_length=500)


    bannerImage = models.ImageField(upload_to=upload_location,
                                    default='shop/defaultimage/default.png',
                                    width_field='widthField',
                                    height_field='heightField')
    widthField = models.IntegerField(default=0)
    heightField = models.IntegerField(default=0)

    likes = models.PositiveIntegerField(default=0)
    dislikes = models.PositiveIntegerField(default=0)
    email = models.EmailField(blank=True)
    mobileNo = models.CharField(max_length=14)
    alternateMobileNo = models.CharField(max_length=15, blank=True)
    location = gis_models.PointField(u'longitude/latitude',
            geography=True, blank=True, null=True)


    ownerName = models.CharField(blank=True,max_length=250)
    shopAddress = models.TextField()
    shopPinCode = models.PositiveIntegerField()



    openingTime = models.TimeField()
    closingTime = models.TimeField()
    closingDay = MultiSelectField(choices=DAYS,default=DAYS[7][0])


    isActive = models.BooleanField(default=0)
    updatedAt = models.DateTimeField(auto_now=True)
    timestamp = models.DateTimeField(auto_now_add=True)

    gis = gis_models.GeoManager()
    objects = models.Manager()

    def __str__(self):
        return self.shopName 

Here is the picture of my time picker

This is picture of json format of openingTime which I am putting through rset api

my django admin (only lower part

Please help by telling what I should do the make the acceptable input time format of time input field

Liam
  • 27,717
  • 28
  • 128
  • 190
Divakar Yadav
  • 107
  • 2
  • 11
  • 1
    It is not clear what you are asking. Directives are an angular concept that have nothing to do with moment. – rmlan Jan 23 '18 at 13:05
  • Their [GitHub page has documentation on all of the provided objects](https://github.com/urish/angular-moment/blob/master/README.md). – Heretic Monkey Jan 23 '18 at 13:07
  • Please read [how to format your questions and answers](https://stackoverflow.com/help/formatting) – Liam Jan 23 '18 at 13:16
  • 1
    Please post all relevant code, tell us the frameworks you are using. For instance, it appears as though `mdc-datetime-picker` is a directive, which likely has formatting capabilities. Also, if you're sending your data over a REST API, then you'll need to convert the data before sending it, in which case we need to see the code where that happens. – Heretic Monkey Jan 23 '18 at 13:24
  • This question is a mess. What exactly are you asking about? Django? Angular? Moment? Please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask). Also please use quotes syntax for **quotes only**, I've had to remove this 3 times now! – Liam Jan 23 '18 at 13:50
  • I am sorry Liam I am new to stackoverflow..also edited it 3 times...I tried my best to represent my problem.. – Divakar Yadav Jan 23 '18 at 13:53
  • 1
    Actually I am trying to explain it here again hope now You'll get it Liam.My Problem is not about Django, angularjs,moment..it is about input format of my timepicker the input time format which it as value is 2018-01-23T12:38:07.439Z I want this format in simple hh:mm:ss – Divakar Yadav Jan 23 '18 at 14:00
  • Ok you state *I am using a timepicker of moment.js* moment doesn't have a timepicker. `mdc-datetime-picker` is not a standard angular timepicker either. So without knowing what `mdc-datetime-picker` is, no one is going to be able to help here – Liam Jan 23 '18 at 14:17
  • You also say the format is showing as `2018-01-23T12:38:07.439Z` yet [this shows otherwise?](https://i.stack.imgur.com/AYTSG.png). Honestly I tried to edit this so it makes sense but I have literally no idea what your asking. – Liam Jan 23 '18 at 14:21
  • [this django admin interface as u told that post everything related to this](https://i.stack.imgur.com/AYTSG.png) – Divakar Yadav Jan 23 '18 at 15:02

1 Answers1

-1

You have to change the format of your database timefield..you cant change the input time format

Divakar Yadav
  • 107
  • 2
  • 11