# Path: stack_configs/influx_functions.py
# def getLastTimeInflux(index,device_id,channel_id):
#     logger.debug ('getting lasttime for device id: %s and channelid :%s',device_id,channel_id)
#     results=getLastInflux(index,device_id,channel_id)
#     datetime="error" 
#     for result in results:
#         logger.debug ('getLastInflux time result %s',result)
#         try:
#             datetime=parse_datetime(result['time'])  
#         except:
#             pass
#            
#     return datetime
# 
# Path: devices/models.py
# class Section(models.Model):
# class Device(models.Model):
# class Channel_tag(models.Model):
# class Channel(models.Model):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def last_published(self):


from django.contrib import admin
from stack_configs.influx_functions import getLastTimeInflux
from .models import Section,Device,Channel,User,Channel_tag
    
    
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        #this function restricts choice of foreign key to those belonging to user/account
        if db_field.name == "section":
            kwargs["queryset"] = Section.objects.filter(account=request.user)
        return super(deviceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)

    
    
    pass   # (replace this with anything else you need)    

class sectionAdmin(FilterUserAdmin):
    
    pass   # (replace this with anything else you need)    

class channel_tagAdmin(FilterUserAdmin):
    list_display=('id','name')
    pass   # (replace this with anything else you need)    


class UserAdmin(admin.ModelAdmin):
    list_display = ('id','username','email', 'first_name', 'last_name')
    

#in case of user must unregister first
admin.site.unregister(User)
admin.site.register(User, UserAdmin)



# Path: stack_configs/influx_functions.py
# def getLastTimeInflux(index,device_id,channel_id):
#     logger.debug ('getting lasttime for device id: %s and channelid :%s',device_id,channel_id)
#     results=getLastInflux(index,device_id,channel_id)
#     datetime="error" 
#     for result in results:
#         logger.debug ('getLastInflux time result %s',result)
#         try:
#             datetime=parse_datetime(result['time'])  
#         except:
#             pass
#            
#     return datetime
# 
# Path: devices/models.py
# class Section(models.Model):
# class Device(models.Model):
# class Channel_tag(models.Model):
# class Channel(models.Model):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def last_published(self):


# Path: devices/admin.py
from django.contrib import admin
from stack_configs.influx_functions import getLastTimeInflux
from .models import Section,Device,Channel,User,Channel_tag

    
    
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        #this function restricts choice of foreign key to those belonging to user/account
        if db_field.name == "section":
            kwargs["queryset"] = Section.objects.filter(account=request.user)
        return super(deviceAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)

    
    
    pass   # (replace this with anything else you need)    

class sectionAdmin(FilterUserAdmin):
    
    pass   # (replace this with anything else you need)    

class channel_tagAdmin(FilterUserAdmin):
    list_display=('id','name')
    pass   # (replace this with anything else you need)    


class UserAdmin(admin.ModelAdmin):
    list_display = ('id','username','email', 'first_name', 'last_name')
    

#in case of user must unregister first
admin.site.unregister(User)
admin.site.register(User, UserAdmin)



admin.site.register(Section,sectionAdmin)